Favicons are the small icons shown in browser tabs, bookmarks and history lists, and they are a long-standing part of the web. One relatively new option is serving the favicon as SVG, which most modern browsers support today, with broader support still arriving.

Wiring up an SVG favicon with fallbacks

Add the following to your site's <head>:

<link rel="icon" href="https://css-tricks.com/favicon.ico">
<link rel="icon" href="https://css-tricks.com/favicon.svg" type="image/svg+xml">
<link rel="manifest" href="https://css-tricks.com/manifest.webmanifest">

And add the matching entry to the web app manifest:

{
  "icons": [
    { "src": "/icon-192.png", "type": "image/png", "sizes": "192x192" },
    { "src": "/icon-512.png", "type": "image/png", "sizes": "512x512" }
  ]
}

The loading order matters. Browsers that support SVG favicons ignore the first link declaration and honor the second one. Browsers without SVG favicon support but with web app manifest support use the higher-resolution images. Everything else falls back to favicon.ico, so any browser that can show a favicon at all gets one.

The second line uses an alternate value for rel, which tells the browser that the .ico file serves specifically as an alternate presentation. The line after the favicons loads another SVG, safari-pinned-tab.svg, which supports Safari's pinned tab feature — this existed before other browsers had SVG favicon support. More files can be added at this point to enhance the site for other apps and services.

The support picture for SVG favicons, per Caniuse, where a number indicates support from that version upward:

Desktop

ChromeFirefoxIEEdgeSafari
8041No8026.0

Mobile / Tablet

Android ChromeAndroid FirefoxAndroidiOS Safari
157160No26.0

What SVG buys you

The .ico format has existed forever and holds images up to 256×256 pixels, so the case for SVG comes down to three things.

  • Ease of authoring. .ico is a proprietary Microsoft format, so producing one requires specialized tools. SVG is an open standard — no extra tooling, no platform lock-in.
  • Future-proofing. A resolution-agnostic file stays sharp on future displays regardless of how large they get, whether that's Retina, 5k or 6k.
  • Performance. SVGs are usually very small files, particularly next to raster alternatives, and more so if you optimize them first. Pairing one with a 16×16 pixel fallback keeps support broad while keeping file size down — and every byte counts.

Styling tricks: emoji and media queries

SVG allows CSS to be embedded directly inside it, so it can be adjusted dynamically with JavaScript — but only when the SVG is declared inline rather than embedded through an img element.

<svg  version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
  <style>
    path { fill: #272019; }
  </style>
  <!-- etc. -->
</svg>

Since SVG favicons are embedded via the link element, JavaScript can't really modify them. Emoji and media queries, however, are fair game.

Emoji as the icon

Lea Verou came up with the idea of using emoji inside SVG's text element to create a quick favicon with a transparent background that holds up at small sizes.

https://twitter.com/LeaVerou/status/1241619866475474946

Chris Coyier built a demo for experimenting with the concept.

Dark mode via prefers-color-scheme

Thomas Steiner and Mathias Bynens independently arrived at the idea of using the prefers-color-scheme media query for dark mode support, building on Jake Archibald's work with SVG and media queries.

<svg width="128" height="128" xmlns="http://www.w3.org/2000/svg">
  <style>
    path { fill: #000000; }
    @media (prefers-color-scheme: dark) {
      path { fill: #ffffff; }
    }
  </style>
  <path d="M111.904 52.937a1.95 1.95 0 00-1.555-1.314l-30.835-4.502-13.786-28.136c-.653-1.313-2.803-1.313-3.456 0L48.486 47.121l-30.835 4.502a1.95 1.95 0 00-1.555 1.314 1.952 1.952 0 00.48 1.99l22.33 21.894-5.28 30.918c-.115.715.173 1.45.768 1.894a1.904 1.904 0 002.016.135L64 95.178l27.59 14.59c.269.155.576.232.883.232a1.98 1.98 0 001.133-.367 1.974 1.974 0 00.768-1.894l-5.28-30.918 22.33-21.893c.518-.522.71-1.276.48-1.99z" fill-rule="nonzero"/>
</svg>

In supporting browsers, the star-shaped favicon switches its fill from black to white when dark mode is active.

Beyond dark mode: other media queries

If prefers-color-scheme works, other queries might too. Support for Level 5 Media Queries may not be fully there yet, but the possibilities include:

  • light-level to desaturate favicon colors in low-light environments.
  • inverted-colors to "flip" inverted colors to preserve branding, or to keep a photorealistic favicon looking as intended.
  • prefers-reduced-motion to remove favicon animation. Animating favicons is best avoided in the first place, since it can trigger ADHD and related disabilities.
  • forced-colors and/or a Windows High Contrast Mode media query to keep the favicon legible in high contrast contexts — and color keywords should be used to keep its colors dynamic.
Mockup of four SVG favicon treatments. The first treatment is a pink star with a tab title of, “SVG Favicon.” The second treatment is a hot pink star with a tab title of, “Light Level SVG Favicon.” The third treatment is a light pink star with a tab title of, “Inverted Colors SVG Favicon.” The fourth treatment is a black pink star with a tab title of, “High Contrast Mode SVG Favicon.” The tabs are screen captures from Microsoft Edge, with the browser chrome updating to match each specialized mode.
A mockup of how these media query-based adjustments could work.

Designing for the pixel grid

Favicons need to look good in the tiny tab area, and the key is aligning the paths of the vector to the pixel grid — the guide a computer uses to turn SVG math into visible bitmap. A simplified square demonstrates the point:

A crisp orange square on a white background. There is also a faint grid of gray horizontal and vertical lines that represent the pixel grid. Screenshot from Figma.

When the square's vector points line up with the artboard's pixel grid, no antialiasing is needed to smooth the shape. When they don't, the result is a "smearing" effect:

A blurred orange square on a white background. There is also a faint grid of gray horizontal and vertical lines that represent the pixel grid. Screenshot from Figma.

Vector points can be snapped onto the grid in an editor such as Figma, Sketch, Inkscape or Illustrator — all of which also export SVG — selecting each node with a precision selection tool and dragging it into position. Complicated icons may need to be simplified to read at such a small size; Jeremy Frank's two-part article at Viget is a good primer.

Additional icon surfaces

Beyond favicons, several (unfortunately proprietary) mechanisms use icons to improve the experience: the Safari pinned tab icon mentioned above, chat app unfurls, a pinned Windows start menu tile, social media previews and homescreen launchers. realfavicongenerator.net is a solid starting point for generating these assets.

Icon output from realfavicongenerator.net arranged in a grid using CSS-Trick’s logo. There are two rows of five icons: android-chrome-192x192.png, android-chrome-384x384.png, apple-touch-icon.png, favicon-16x16.png, favicon-32x32.png, mstile-150x150.png, safari-pinned-tab.svg, favicon.ico, browserconfig.xml, and site.webmanifest.
It’s a lot, but it guarantees robust support.

How the favicon got here

Internet Explorer was the first browser to support favicons, and the feature was snuck in at the 11th hour by developer Bharat Shyam:

As the story goes, late one night, Shyam was working on his new favicon feature. He called over junior project manager Ray Sun to take a look.

Shyam commented, "This is good, right? Check it in?", requesting permission to check the code into the Internet Explorer codebase so it could be released in the next version. Sun didn't think too much of it, the feature was cool and would clearly give IE an edge. So he told Shyam to go ahead and add it. And just like that, the favicon made its way into Internet Explorer 5, which would go on to become one of the largest browser releases the web has ever seen.

The next day, Sun was reprimanded by his manager for letting the feature get by so quickly. As it turns out, Shyam had specifically waited until later in the day, knowing that a less experienced Program Manager would give him a pass. But by then, the code had been merged in.

From How We Got the Favicon by Jay Hoffmann

Whether Safari will implement SVG favicon support is unknown at this point. For now, the SVG favicon plus fallback arrangement above keeps every browser served while letting supporting browsers get the sharper, more flexible icon.