Changing the favicon in dark mode
How to display a different favicon in dark or light mode
If you have a Mac set up to automatically switch between dark and light mode, you may have encountered the issue of having a white favicon that becomes almost invisible in light mode. Let’s explore how we can add a favicon in dark mode and a different one in light mode.
Unfortunately, there isn’t a straightforward way to achieve this for PNG/JPG bitmap images. However, we can use an SVG (Scalable Vector Graphics) trick to accomplish our goal. By embedding CSS within an SVG image, we can modify the color in dark mode, allowing us to have different colors for the two modes.
Here’s an example of an SVG file that can be used as a favicon:
1 | <svg |
As you can see, the SVG image is simple and displays a half moon. The fill color of the path is set to #ccc
in light mode and #fff
in dark mode. This differentiation in color allows the favicon to be visible in both modes.
After saving the SVG file, you can use it as the favicon in your Gatsby website or any other appropriate platform.
Tags: dark mode, light mode, favicon, SVG