ryoblog/src/blog/darkmode-should-be-default/index.md

3.5 KiB

title: For accessibility sake, dark theme should be the default, and not require JavaScript author: 寮 date: 2022-06-24 16:12:00 tags: blog,technology,webdev,internet threadid: AKo3N6G87Byl4dB76O

It's a trend these days to offer an optional dark theme alongside the eye bleeding light theme.
This is a step in the right direction, considering how only a few years ago we all had to suffer under the light theme, because everyone stopped providing dark theme, colorful theme, or something else that's easy for the eyes, or otherwise use the Lynx browser so we can view content in any color we wanted, or simply boycot it altogether if there's no way to access the websoyte without JavaScript.

Preferably, the dark theme should be the default theme, rather than optional.
Even if the default is the light theme, dark theme should work even with JavaScript disabled.
Because as weird as it sounds, many of such websites will refuse to give you the dark theme unless you enable JavaScript.
Apart from forcing people to enable it to push ads down your throat and spy on you using ANALytics soyware, I fail to see why you'd want to force people to enable JavaScript at all.

Honestly, I have no idea why the fuck we need to use JavaScript in order to have the right colors.
What's so hard about storing the preferred theme into cookies, and apply the CSS for the theme you selected?
We accomplished exactly that 2 decades ago already, so I don't see how we can't accomplish that today.

This blog doesn't have a theme switcher, but that's simply because there's no need for it.
I designed this site to be a sweet spot between the light theme clan and dark theme clan, and I did that by making the theme red and yellow.
I used to do red+green+white, but I found it to be pretty painful to the eyes, so I changed to red+yellow.
And before that it used to be black+white+red+green+blue+yellow, but that was simply because I was still yet to design a theme, so it served as a temporary theme.

Speaking of accessibility, it's important for dark theme to work without JavaScript too, because if it doesn't, then your site is NOT accessible at all.
If you care about accessibility so much, it should work on any browser under any settings.
This includes being able to view the website with the Lynx browser via Tor, if your website is unviewable that way, even though less than 1% of the world would ever do that, then your website is NOT accessible at all.
Even the tiny things like being able to use the Tab key to get through a form, and being able to press the Enter key to submit a form (except for textarea, that one is designed to be able to use the Enter key for new line) without JavaScript contributes to accessibility.

Speaking of forms, stop doing form validation with JavaScript, it should always be done on the backend.
Every single good web developer with no exception will tell you the following: never trust the client side, AT ALL!!
Form validation on the client side can easily be manipulated.
One example of that is what loli frog told me about Mixi.
Apparently on Mixi you can bypass the 150 character limit by simply disabling JavaScript.
Usually you won't be able to submit messages on your account's wall if the amount of characters goes beyond 150 characters, but if you disable JavaScript, your message can be any amount of characters you want, and it'll get published without any problems whatsoever.
So clearly they don't do any form validation at all in the backend, only frontend.