What Is the Easiest Way to Add Dark Mode to a Website? Part 2
In a previous post, I mentioned how to add dark mode to a website. Let’s take this one step further by letting users choose the color pallete they prefer in spite of the default browser color scheme.
The first step is to create a function that will detect the loaded color scheme and sets the opposite color scheme with placeholders for setting functions setting the colors.
This function will load my style sheet from the document and gets the –main-bg-color variable.
As according to my stylesheet if the variable is set to #f7f7f7, then the user is being served the light theme or else they are served the dark theme.