Ronalds Vilciņš

Dark mode for SVG favicon

You can embed CSS within an SVG with a <style> element. This means that you can style your icon with inline prefers-color-scheme.

<!-- icon.svg -->
<svg width="100" height="100" xmlns="">
    circle {
      fill: white;
      stroke: black;
      stroke-width: 2px;
    @media (prefers-color-scheme: dark) {
      circle {
        fill: black;
        stroke: white;
  <circle cx="50" cy="50" r="47"/>

For Safari, it’s a bit different. You need to add a mask-icon. It’s also an SVG, but it has to be made of a single colour and placed on a transparent background. You specify the color, so there is no opportunity there for a dark mode situation.

<link rel=”mask-icon” href=”mask-icon.svg” color=”#000000">