Skip to content

Making SVGs Dark Mode Ready

Image assets, especially SVGs, are often an afterthought when building websites with dark mode support.

2 min read
SVG
Dark Mode
Light Mode
CSS
Media Query

Image assets, especially SVGs, are often an afterthought when building websites with dark mode support. Have you ever been browsing a dark-themed site only to be blinded by a pitch-black icon or illustration? It just disappears into the background because the contrast is gone.

The fix is actually pretty simple: you can make your SVGs adaptive by dropping a little bit of logic directly into the file using a <style> tag. By using the prefers-color-scheme media query, you can tell the elements inside the SVG, like strokes or circles, to change color automatically based on the user's system theme.

Support for this is already massive (over 96% according to caniuse), so you don't really need to worry about compatibility for most users.

There’s also a fun, if slightly risky, idea: using adaptive SVGs for favicons. Imagine your browser tab icon changing colors to match the system theme; it gives off a very premium feel. That said, SVG favicon support is only around 76% right now.

Because of that, it's still smart to set up a fallback for older browsers. You don't always have to chase the latest tech, but having a backup is just good practice for the user experience.

At the end of the day, making one "smart" SVG file is much more efficient than managing two separate images. It’s these small details that make a product's visuals feel polished and well-integrated.