Light/Dark Templates With Scripting Off Graceful Degradation

Jason Knight
CodeX
Published in
5 min readDec 12, 2022

--

One of the problem with a lot of stuff done on websites these days is the lack of scripting off/blocked/disabled support. In my previous article:

I actually jumped the gun by making it a scripting only solution. Mind you, as a scripting off solution light/dark shouldn’t be an accessibility woe if you have chosen legible contrasts, but as a user posted in the comments it would be nice to have that functionality.

When implementing this we have a problem as we’re undoing one of the major points in that previous article. To make it work we HAVE to send screen only markup to non visual UA’s. That’s bad, but a sacrifice you have to make if you want screen users with scripting blocked to have this functionality.

I was originally going to hold off on this until another article I’m working on is “ready” to combine this in, but I’m moving it up the list as it’s quick and easy to implement. We’ll use PHP in this case, but you folks should be able to port it quickly to any server-side language.

Server Side

Generating our markup from PHP is pretty simple. To make this easier to understand I’m just going to use sessions, so the big “scripting part” we…

--

--

Jason Knight
CodeX

Accessibility and Efficiency Consultant, Web Developer, Musician, and just general pain in the arse