News for hackers. Stuff that matters.
Re:Dark mode in a website with CSS by fastball on Tuesday October 08, 2019 @08:34PM (#21198772)
Is there anything which allows user choice (i.e. state) that doesn't involve JS?
Re:Dark mode in a website with CSS by RobertKerans on Wednesday October 09, 2019 @02:56AM (#21200748)
Checkbox + CSS custom properties for the colours/font weights etc . Checkbox checked, adjust the variable values.

There's normally a little more to it than that, but there shouldn't ever be _much_ more, custom properties are fully dynamic

Re:Dark mode in a website with CSS by agret on Tuesday October 08, 2019 @08:55PM (#21198916)
Yes, although doing things without JS is old school web. I think you'd be hard pressed to find any clients that don't support JS in this era.

Anyway, to accomplish this you would split your styles into seperate CSS files and then have a drop-down that does an HTTP POST/GET to a server side script that will then set a cookie on your browser with your preferred choice.

Each time a request comes in from the client you just check that cookie for which style they want and then change the HTML that's sent to include a different stylesheet.

Re:Dark mode in a website with CSS by nine_k on Tuesday October 08, 2019 @09:29PM (#21199105)
There's a number of end users who would like to avoid JS on non-app sites.
Re:Dark mode in a website with CSS by toastal on Wednesday October 09, 2019 @10:21AM (#21203518)
There's also alternative style sheets (https://developer.mozilla.org/en-US/docs/Web/CSS/Alternative...), that can support the media queries on the tags, but I think Firefox is the only browser still exposing the ability to switch the styles, and it sadly don't persist between sessions or even a page navigation/refresh.
Re:Dark mode in a website with CSS by dgb23 on Tuesday October 08, 2019 @08:47PM (#21198858)
You can use checkbox inputs (the reason why HTML&CSS is turing complete)
Re:Dark mode in a website with CSS by Zenbit_UX on Tuesday October 08, 2019 @09:33PM (#21199125)
Yes, you can use an html checkbox and monitor its state with pure css.