I've been a professional C, Perl, PHP and Python developer.
I'm an ex-sysadmin from the late 20th century.
These days I do more Javascript and CSS and whatnot, and promote UX and accessibility.
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.
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 😉
I'm a web sysop and support engineer. My skills are mainly in back-end: Java, Linux, Python, PostgreSQL, Git, and GitLab. Currently I'm learning front-end skills: JavaScript, and Ruby.
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.
This is the way! 🥳
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 😉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.
Sweet!