79659011

Date: 2025-06-09 14:19:01
Score: 1
Natty:
Report link

Safari makes this really tricky.

In most browsers, using multiple favicons with media="(prefers-color-scheme: dark)" or even a fancy SVG that changes with CSS works great. But Safari? Not so much.

Here’s what’s going on:

So… is there any way to make it work?

Option 1: Do it on the server (if you can)

If your site is server-rendered, you could try to serve a different favicon based on the user’s system theme. This involves detecting their preference before the page loads (which is tricky but possible in some setups using headers or early JavaScript). But honestly, it’s not super reliable and pretty advanced to pull off cleanly.

Option 2: JavaScript with a little hack

You can try forcing a favicon reload using JavaScript like this:

const dark = window.matchMedia('(prefers-color-scheme: dark)').matches;
const link = document.createElement('link');
link.rel = 'icon';
link.href = dark ? 'dark-icon.png?v=' + Date.now() : 'light-icon.png?v=' + Date.now();
document.head.appendChild(link);

This sometimes works — by adding a timestamp, you trick the browser into thinking it's a fresh file. But again, Safari is stubborn and may ignore this too.

Option 3: One neutral favicon

Honestly, the most reliable thing you can do is pick a single favicon that looks good in both light and dark mode. Something with a little border or contrast so it stands out no matter what.

TL;DR:

Safari just doesn’t play nice with dynamic favicons. You can try some workarounds with JavaScript, but they’re hit-or-miss. If it’s important for your brand, go with a high-contrast favicon that works in both themes.

Reasons:
  • Blacklisted phrase (1): is there any
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: Ishanvi Chauhan