Live data from Hacker News

The Future of CSS: Easy Light-Dark Mode Color Switching with Light-Dark()

bram.us

31–40 of 74 posts

Re: The Future of CSS: Easy Light-Dark Mode Color Switching with Light-Dark()

#31
If people envisioned that web would become an application platform, maybe we wouldn't have CSS and HTML but instead some sort of lower level bytecode (ala WASM) and the actual higher level document and styling tools would be separate and compile to this bytecode. It makes me shutter every time I imagine how much you have to cover from CSS and HTML alone for a function web browser.

This method is pretty much ternary operator and it requires a browser support to be used, insanity.

Re: The Future of CSS: Easy Light-Dark Mode Color Switching with Light-Dark()

#32

A genuinely useful behaviour of a function like this would be to return the colour with most contrast over the background of its container element, rather than a predefined colour scheme. I know that’s not how CSS works.

Even though that’s a kind of strange and unworkable idea — it’s interesting to think about.

Unworkable in the sense that, for example, some elements are not physically positioned inside their container elements, and sometimes even in light dark mode you might use elements to create subtle layering etc, where you’d want the least contrast.

It wouldn’t be too difficult to write a gimmick webpage though, that implements the idea, to see what kind of fun would ensue.

I’ve got some sample code here that uses the little known but very powerful “tree Walker” to change elements 1 by 1.

https://til.secretgeek.net/css/replace_text_with_property_va...

And you can write javascript code that alters css variable values like this:

var root = document.documentElement; root.style.setProperty('--main-hue', 0);

I think the particular can of worms you’re suggesting could be very strange and interesting!

Re: The Future of CSS: Easy Light-Dark Mode Color Switching with Light-Dark()

#33
post #21

I've done a LOT of dark mode work, to the point where I'd consider myself an expert here[1]. I'm not a fan of this. This solves one tiny aspect of the larger problem in a non-scalable way that will inevitably lead to bloat and inflexibility. It's a really a naive approach that hasn't taken into account design at scale, nor the future of where design is heading. Typically when doing theming, you have two axes - a visu…

Remember that the projects you work on are not typical of most CSS usage in the world.

For small projects that never need to "scale", this looks handy.

Re: The Future of CSS: Easy Light-Dark Mode Color Switching with Light-Dark()

#34

How does this deal with the ternary of light/dark/high-contrast that a lot of sites are now using? I wish they would just enable features that are already in the browser that they've not put live, like grid-template-rows: masonry. All three major engines have the damned thing in there but it's not in release branch.

There's also the light/dark/system (auto) ternary approach, which this seems to encourage the designer to ignore in favor of a binary toggle. It seems to beg the developer to treat the mode as a negation of whatever it currently is, which leads to bad results and time-dependency of setting.

Re: The Future of CSS: Easy Light-Dark Mode Color Switching with Light-Dark()

#35

How does this deal with the ternary of light/dark/high-contrast that a lot of sites are now using? I wish they would just enable features that are already in the browser that they've not put live, like grid-template-rows: masonry. All three major engines have the damned thing in there but it's not in release branch.

if browsers have support for a feature such as masonry, but it is not enabled in css spec does that mean it cannot be used? I recall seeing masonry in a tailwind talk, very neat!

Well, most people implement it using JavaScript if you want everything to be in the correct order. I use a pure CSS variant as I'm trying to go near-zero JS on my projects these days, but it means things are out-of-order. Depends on your use case.

I also check for CSS support in the browser using the "supports" feature and utilize the native support if it is enabled (e.g. Firefox behind a flag, and Safari behind a switch).

Re: The Future of CSS: Easy Light-Dark Mode Color Switching with Light-Dark()

#36
post #34

How does this deal with the ternary of light/dark/high-contrast that a lot of sites are now using? I wish they would just enable features that are already in the browser that they've not put live, like grid-template-rows: masonry. All three major engines have the damned thing in there but it's not in release branch.

There's also the light/dark/system (auto) ternary approach, which this seems to encourage the designer to ignore in favor of a binary toggle. It seems to beg the developer to treat the mode as a negation of whatever it currently is, which leads to bad results and time-dependency of setting.

Exactly. I'm not sure this is totally thought-out.

p.s. love your work

Re: The Future of CSS: Easy Light-Dark Mode Color Switching with Light-Dark()

#39
post #33
post #21

I've done a LOT of dark mode work, to the point where I'd consider myself an expert here[1]. I'm not a fan of this. This solves one tiny aspect of the larger problem in a non-scalable way that will inevitably lead to bloat and inflexibility. It's a really a naive approach that hasn't taken into account design at scale, nor the future of where design is heading. Typically when doing theming, you have two axes - a visu…

Remember that the projects you work on are not typical of most CSS usage in the world. For small projects that never need to "scale", this looks handy.

Even if you never need to scale, Having light/dark & high contrast is just having basic features and complying to the law. If your site has 50 users it should have these, and this new light/dark switch is still inappropriate for even this basic use case.
Post reply on HN