Tech
A practical CSS variable setup for light/dark mode without theme flash
Dark mode is easy to start.
It is harder to ship cleanly.
Most implementations need to handle:
light mode
dark mode
system preference
stored user preference
a toggle button
no flash of the wrong theme on page load
The flash is the annoying part.
You save the user's choice in localStorage , but your app JavaScript usually runs after the browser has already started parsing HTML and CSS.
So the page may briefly render in the wrong theme before your JavaScript applie...
Read the full discussion on Dev.to
This article was aggregated from Dev.to. Click to join the conversation.
View on Dev.to