5 ms·
This is why I think they should focus on exposing the dark mode setting in Javascript instead of CSS. Sites that support dark mode should (and will almost alwa
by morley 8y ago
This is why I think they should focus on exposing the dark mode setting in Javascript instead of CSS.
Sites that support dark mode should (and will almost always) have a toggle for it. It'd be better if this setting helped _inform_ the default initial state rather than _forcing_ a choice on you. To me, that's a lot easier done with a Javascript API than CSS.
- yunyu 8y agoYou'd be able to do this with the matchMedia API: https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia https://developer.mozilla.org/en-US/docs/Web/API/Window/matc...
- morley 8y agoI didn't know about that, thanks for that!
- codazoda 8y agoYou could easily apply or remove the css via Javascript to allow enable / disable of the feature.
- giobox 8y agoExactly. This is going to be the simplest browser extension anyone has ever written, if someone hasn’t done so already.
- stephenr 8y agoMore javascript is almost never the best solution to any problem, particular when it’s shown that css can achieve the same result.
- morley 8y agoMy argument is that CSS doesn't achieve the same result; it forces one particular mode on you instead of allowing a choice.
- stephenr 8y agoYou have all the choice in the world. Use whatever tech you want (browser js, server side templating, client side xslt, etc) to have an attribute on the body element indicating opt-in status, and use that in your media query to target only the users who want it. With the css solution it’s doable on a site that has no javascript.
- int_19h 8y agoThe right place for the switch in this case is the browser. The browser should have a button for light/dark/system, defaulting to system. And CSS should follow that. JS should not be involved, and we don't need every site to have its own version of the switch, located in a different place and looking different.
- reaperducer 8y agoYou don't need Javascript to implement a switch that changes from light mode to dark mode. That can be easily done in CSS. I've done it on web sites to switch to a high-contrast color scheme for people with vision difficulties.