Although I don’t recall any by name, I’ve seen a handful of themes that allow for this.
As well, and although I’m not able to copy and paste the code right now since I’m away from my laptop at the moment, but if you’re competent with CSS and JS you can grab the requisite code off of my blog which has its own way of allowing for this. If you’re interested, let me know and I can copy/paste over the requisite code tomorrow.
If you still want the code, here it is, although don’t ask me about it since I don’t know JS. Furthermore, my dark mode functionality uses a toggle, which may very well be a part of the JS (just the first three lines?). And last of all, my dark mode functionality no longer detects the system dark/light setting as I preferred it defaulting to light mode. That being said, if you switch over to dark mode it’ll stay that way.
Following that, all classes that you want to switch over when you activate the toggle (or button?) will have to be preceded by body.dark. So for example, if for light mode you have
p {
color: #000;
}
then for dark mode you’d have
body.dark p {
color: #fff;
}
I could be mistaken, but I think the code was adapted from here:
Otherwise, I was able to find one blog in my bookmarks that uses a button for its dark mode functionality (it’s in the hamburger menu):
hi, sorry if I answer only now but I didn’t have the time.
I was able to use the color change with the toggle from the front-end but without respecting the default settings of the css.
Creating custom css classes and using javascript as you did is good.
But i would like to run both the toggle button and the automatic system detection mode.
I’m looking for a solution to enable @media (prefers-color-scheme: dark) {} with the button, without having to create other css classes or other files
It’s a built in feature as part of the browser. If the operating system is using a dark colour scheme the browser will respect that and provide a flag, prefers-color-scheme: dark, to allow site developers to also respect the users colour scheme preference. Being able to toggle it within the site would be a feature on top of that
@tvdsluijs you can effectively override the browser and force your site to ignore the user’s browser dark mode settings (make it always be either light or dark or whatever you want) by just NOT providing the alternative dark mode styles.
If a theme already has the darkmode built in, as Casper, you can remove it: