←back to thread

451 points todsacerdoti | 1 comments | | HN request time: 0s | source
Show context
sbinnee ◴[] No.45060391[source]
I always knew that there should be a way to have a button to change light and dark mode on my website without javascript. But I couldn’t figure it out (pre llm era) and gave up and just used javascript. Now it’s time to make an update on that. This blog motivated me.
replies(3): >>45060405 #>>45060700 #>>45062138 #
1718627440 ◴[] No.45062138[source]
If your intention is to let the user choose between styles the best way would be Alternate Stylesheets: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/... . Sadly Google can't be bothered to implement "legacy" standards (=standards not invented at Google).

If your intention is to adopt your styles slightly to user preferences then there are media queries.

replies(1): >>45067566 #
Telaneo ◴[] No.45067566[source]
Alternate stylesheets don't persist (at least in Firefox), which is really annoying.

Media queries are really nice though. Being able to provide a night mode alternative without even asking the user, assuming they've set the OS to their preference, is really seamless.

replies(1): >>45069384 #
1. 1718627440 ◴[] No.45069384[source]
> Alternate stylesheets don't persist (at least in Firefox), which is really annoying.

Yes, I also think they should. What I wondered, is this behaviour prescribed somewhere? Even if it were, form content is retained even across randomly typing in a different URL and navigating back, form submission and even across real crashes just seconds after I typed the letter. This is really nice and I don't think it is mandated. This is the stuff User Agents should be compete with, not ways to get data from the User to a surveillance company.

> Being able to provide a night mode alternative without even asking the user, assuming they've set the OS to their preference, is really seamless.

Yes, that's nice and how every thing in a UI should be. It helps both the programmer and the user in efficient and controllable usage.