4 ms·
Original author here. I don't like the idea of using JS on my website and I don't think that it is possible to create a light/dark mode switch with only CSS. Bu
by dulvui 3y ago
Original author here. I don't like the idea of using JS on my website and I don't think that it is possible to create a light/dark mode switch with only CSS.
But you are right, most users don't know how to do that.
- jiggywiggy 3y agoWould be perfectly reasonable to use js over this feature.
- dulvui 3y agoYes for sure, but my personal policy is not using JS. Anyway my site doesn't have so many visitors ;-) People come, stay for a few seconds and then leave forever.
- jiggywiggy 3y agoHahah old school hate for js. Very good.
- FireInsight 3y agoHowever, it would probably be possible with very minimal JS a la how Tailwind does it, toggling a .dark class in the body element and setting the dark mode variables and colors there.
- butz 3y agoBut adding onclick and window.open() JS functions is somehow justifiable, over using simple <a> links? Of course, there might be some specific case you are solving here, so it would be very educational to hear this out.
- danielheath 3y agoYou can! Trick is to use the checkbox:selected hack to apply styles, in addition to the colour-scheme media query.
- CrimsonRain 3y agoIt is possible; just too convoluted/subpar imo. You can use a checkbox's check/uncheck status. One such codepen from quick google: https://codepen.io/shadowfaxrodeo/pen/JjbzNMz https://codepen.io/shadowfaxrodeo/pen/JjbzNMz
- dulvui 3y agoCool thank you for sharing this! I might implement this on my site.