DEV Community

Discussion on: Light and dark mode in just 14 lines of CSS

Collapse
 
moopet profile image
Ben Sinclair

This is the way. I've never been a fan of using Javascript to switch themes. I've never actually implemented it before but if and when I do I'll do it your way. It might not work on every system yet, I'm not sure? But it'll get there in time if it doesn't.

Collapse
 
whitep4nth3r profile image
Salma Alam-Naylor

This is the way! 🥳

Collapse
 
pcjmfranken profile image
Peter Franken

Here's a compatibility overview for the three major components to this implementation: caniuse.com/prefers-color-scheme,c...

The prefers-color-scheme is rather essential for pegging your css to the user's system theme, but the :root pseudo class and even the custom properties / variables could be left out - although that'd mean nesting all your css within those media queries 😉

Collapse
 
sinewalker profile image
Mike Lockhart

I use a static blog generator with a light theme that I have overridden by hand. Now with this idea I can just wrap my overrides in the media query.

Thread Thread
 
whitep4nth3r profile image
Salma Alam-Naylor

Sweet!