For decades, web developers relied on static .ico files that looked decent on white browser tabs but turned nearly invisible when operating systems introduced system-wide dark modes. Modern browsers now fully support SVG favicons containing embedded CSS media queries.

Why Legacy Favicons Fail in Dark Mode

Traditional favicon.ico and PNG assets use fixed colors. When a user with macOS or Windows in Dark Mode opens a browser like Google Chrome, Safari, or Brave, the tab bar turns into dark slate or charcoal.

If your logo relies on dark or black shapes, it becomes completely illegible against the dark tab header. Conversely, light-themed icons can produce glaring contrast on light tabs unless handled adaptively.

How SVG Embedded Media Queries Work

An SVG is essentially an XML document that natively supports CSS <style> elements. You can write standard CSS rules inside the SVG markup that listen for the user's OS color scheme preferences.

When the browser renders the tab bar icon, its internal SVG engine evaluates @media (prefers-color-scheme: dark) in real-time without requiring any JavaScript on the host page.

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
  <style>
    :root {
      --bg: #3b82f6;
      --fg: #ffffff;
    }
    @media (prefers-color-scheme: dark) {
      :root {
        --bg: #0f172a;
        --fg: #38bdf8;
      }
    }
    .background { fill: var(--bg); transition: fill 0.3s ease; }
    .glyph { fill: var(--fg); }
  </style>
  <rect width="100" height="100" rx="22" class="background" />
  <text x="50" y="66" font-size="48" font-family="system-ui" font-weight="bold" text-anchor="middle" class="glyph">✦</text>
</svg>

Engineering Note: Notice how transition properties are even supported in modern browser engines, providing seamless animated transitions when the system theme toggles.

HTML Declaration & Cross-Browser Fallbacks

To ensure universal compatibility across legacy clients and modern browsers, provide the SVG favicon first with sizes="any", followed by a multi-resolution favicon.ico as a fallback.

<!-- 1. Modern Vector Favicon with Dark/Light Support -->
<link rel="icon" href="/icon.svg" type="image/svg+xml" sizes="any" />

<!-- 2. Legacy Fallback for Safari Pinned Tabs & Old Clients -->
<link rel="icon" href="/favicon.ico" sizes="32x32" />

<!-- 3. iOS Full-Bleed Touch Icon -->
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />