Not if you blockingly inline the three lines of JavaScript with a good old script tag right in the HTML.
That way you will have a flash, but if the user set dark mode on their browser/DE, they'll flash in dark, not light.
Or, alternatively, you can always make it flash in dark. I never heard about anybody being annoyed by a dark flash.
I'm not aware of the specifics of regulations in other parts of the world, but this distinction is irrelevant for the EU ePrivacy directive: a) it was never about cookies only, and b) purely functional cookies that record user preferences do not need explicit consent.
From [0]:
> 34,35 Storage of information in the sense of Article 5(3) ePD refers to placing information on a physical electronic storage medium that is part of a user or subscriber’s terminal equipment [..] this includes making use of established protocols such as browser cookie storage as well as customized software, regardless of who created or installed the protocols or software on the terminal equipment.
> 43 This might also be the case for web browsers that process information stored or generated information [sic] inside the device (such as cookies, local storage, WebSQL, or even information provided by the users themselves). The use of such information by an application would not be subject to Article 5(3) ePD as long as the information does not leave the device
https://www.edpb.europa.eu/our-work-tools/documents/public-c...
Doesn’t bother me enough to change the technique at this time, but I’ve put it in the things to do list.
I like the idea of having it automated by the system-set user preference in addition to having an option to set it manually with a link.
Thank you for illustrating the fact that the phrase "best practice" means nothing, and is little more than a synonym for "I heard this somewhere."
I remember Firefox used to have an option in the menu for selecting alternative stylesheets, multiple ones not just light and dark, I think it was a standard from CSS, but only Firefox had a way to select them through the UI, for other browsers you had to use Javascript to make a selector.
Presumably, most users wanting flashbang-less browsing experience use Dark Reader extension or similarly radical solutions.
The sad truth is that the user preferences and per-site persistence for stuff like this should always have been browser's responsibility to begin with: just the same way like the font-size/page zoom already is, and likewise some (blatantly limited) security settings. (Bitterly) amusing fact is that there was (and still is) concept of "alternate stylesheets" from the beginning of CSS (still part of the spec [0], no support outside Gecko), that also fade into obsolescence for it's lack of persistence. So to this days, Firefox, for example, has View → Page Style menu, where user can choose alternate stylesheet but the choice is not preserved across navigations, so is pretty useless on its own.
Similarly userstyles: specifications dictate there is like CSS origin level and how they should behave and that all "user agents" are supposed to give user a way to enter the cascade this way, but does not give any official way how to scope individual recipes to concrete origins. That's what the unofficial `@-moz-document` extension was that, and briefly had a chance to be formalised [1]. But I digress.
(Likewise all the "European" cookies banners: tragic example of regulation applied on the wrong level. Instead of putting users in charge with help of their "user agents": implicitly blocking pretty much everything and using permissions system that actually would have a chance to be more than "pinky promise we will not track you if you don't click this toggle inside our banner". But I digress even more, sorry.)
> I'd be curious to know if anybody has found a way to avoid this issue with JS switchers -- ideally without needing to delay the initial paint.
At this point, when browsers do not support per-site user preference for that natively, pragmatic (most robust) way would be to respond with properly set HTML payload straight away. There is even specified HTTP header for this, so once adopted in browsers, we could even ditch HTTP cookies [2] for the persistence, but it seems quite demanding on the server (IIUC negotiating these "Client Hints" takes extra initial request round-trip).
Pragmatically, I guess having early running JS in the HEAD that ensures the proper color-scheme is set on the root not and only proper stylesheets load should pretty much prevent most flashbangs, provided the relevant bit would arrive early enough from the server. I think there does not exist any good no-JS-no-Cookie (or any JS-less persistence) solution that supports navigations, sadly.
[0] https://html.spec.whatwg.org/multipage/links.html#rel-altern...
[1] https://www.w3.org/TR/2012/WD-css3-conditional-20121213/#cha...
[2] https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/...
Most browsers also support per-page overrides, but the only consistent place to find it is Dev Tools, which is a shame.
I think browsers decided to invest in "Reader Mode" as a UX over more direct control of user styles and page styles, and I'm not always sure that is the correct choice, but I can understand how it seems the simpler "one-button" choice.
I feel the same way about salads in restaurants—I don’t want to have to slice produce, add dressing, and toss my own salad at the table without a bowl or proper utensils. I want the professionals who I am paying to prepare my meal to handle that. If I have problems with any of the ingredients, or some desire for unreasonable quantities of dressing, then I can make requests. Serving me a plate of neatly partitioned ingredients strikes me as an insane thing to do…I suppose unless it comes with fondue or I have signed up for some hibachi nonsense to make my dinner more “interactive”.
I have fully lost the thread, apologies, carry on.
The ideal web would give the option of better separating form and function when possible. I'm well aware that this is an old set of values from another time, but today they're more important than ever, not just aesthetically, but with reference to ability and power and dare I say, freedom.
Calling this a “sad state of affairs” is pretty dramatic. You have to gaze upon things that aren’t in your preferred colors, oh my!
This was trivial for websites 15 years ago, but due to increasing complexity, it's no longer feasible. We've put more and more styling type things in JS, which really undermines web as a platform.
This is why CSS exists. This isn't some weirdo use case, this is THE use case. We're all losing the plot.
Which is fine. Most software is shit, so they should feel right at home. I'm just not going to pretend that the current state of web applications is at all acceptable.
It's awful in so many ways. Awful, awful, awful.
What would you do if you had the option to choose any font of your choosing? What color for the headers? The background of the buttons? Should you be able to define the border radius? The CSS transitions? All of CSS?
You can do that. There are extension for that.
I don't think this is a concern for the vast majority of users.
It is ludicrous to expect every web page to give the user control over individual theme elements. If you want such level of control, you can override them yourself with a custom style sheet.
It can make sense for a theme selector that works on the server, since you can serve specific HTML when building the page. However, if using a JavaScript-based solution that fetches the theme preference from localStorage, I find this almost always results in a "flashbang" in dark mode, as the retrieval is slower than the first browser paint.
I've been implementing (and recommending) pure CSS-based theming to avoid this problem. Users seem much happier with them, and I haven't heard anybody ask for a theme switcher. We just respect their existing preference. However, I can see this being a problem if you offer multiple color schemes (beyond just light and dark).
I'd be curious to know if anybody has found a way to avoid this issue with JS switchers -- ideally without needing to delay the initial paint.
I do think an interesting approach would be a browser extension that lets you override the prefers-color-scheme property on a per-domain basis, similar to the toggle in dev tools.