CSS:
@media (prefers-color-scheme: light) {
:root {
color-scheme: light;
}
}
@media (prefers-color-scheme: dark) {
:root {
color-scheme: dark;
}
}
:root:has(dark-mode-toggle[mode="light"]:not(:state(dark))),
:root:has(dark-mode-toggle:state(light)) {
color-scheme: light;
}
:root:has(dark-mode-toggle[mode="dark"]:not(:state(light))),
:root:has(dark-mode-toggle:state(dark)) {
color-scheme: dark;
}
The hoops you jump through to battle FOUC when <dark-mode-toggle> is a #webcomponent with custom dark/light states, but all the JS magic may need some time to load, so there's also a content attribute for the initial state, but that may in turn be overridden by user choice (= custom states) 🥴
#css