News for hackers. Stuff that matters.
Re:The Future of CSS: Easy Light-Dark Mode Color Switching w... by swatcoder on Monday October 09, 2023 @06:39PM (#37826338)
Oof. Unless I’m missing something, this is a convenience that doesn’t enable anything new and uses syntax/terms that don’t naturally generalize for future applications. It just embeds one recent trend in very specific, very rigid terms.

This is how standards get bloated.

Re:The Future of CSS: Easy Light-Dark Mode Color Switching w... by incrudible on Monday October 09, 2023 @06:47PM (#37826414)
God forbid someone adds practical features for common use cases to our beautiful turing tarpit.
Re:The Future of CSS: Easy Light-Dark Mode Color Switching w... by swatcoder on Monday October 09, 2023 @07:12PM (#37826635)
You can have both. But good tool design looks at the horizon, not just at your feet.

You could deliver the same convenience in a way that’s set up to be repurposable (fullcolor /rgcolorblind) or extensible (light / grey / dark / …n) with as little difference as choosing a more mindful name.

Re:The Future of CSS: Easy Light-Dark Mode Color Switching w... by imachine1980_ on Monday October 09, 2023 @06:58PM (#37826509)
I agree with the previous comment that the current approach lacks flexibility in achieving high contrast. It might be beneficial to consider a more general and adaptable method that can accommodate different styles or even introduce primitives for different styles in the future
Re:The Future of CSS: Easy Light-Dark Mode Color Switching w... by miragecraft on Monday October 09, 2023 @07:24PM (#37826728)
I agree.

You can already do this using the space toggle technique:

:root { --dark: ; }

@media (prefers-color-scheme: dark) { --light: ; --dark:initial; }

.example { color: var(--light, #000) var(--dark, #fff); }

Re:The Future of CSS: Easy Light-Dark Mode Color Switching w... by Kerrick on Monday October 09, 2023 @08:18PM (#37827094)
Ah yes, the CSS Space Toggle. The way this works internally is a seemingly-unintended but very useful aspect of the CSS specification.
Re:The Future of CSS: Easy Light-Dark Mode Color Switching w... by zeroimpl on Monday October 09, 2023 @08:20PM (#37827115)
That looks awful, but presumably if you are using sass instead of css you could define a light-dark macro already which does exactly that.

I wonder if custom functions might ever make their way to css.

Re:The Future of CSS: Easy Light-Dark Mode Color Switching w... by miragecraft on Tuesday October 10, 2023 @10:04AM (#37832259)
Correction, the media query should have been:

@media (prefers-color-scheme: dark) { :root { --light: ; --dark:initial; } }

Missed the selector.

Re:The Future of CSS: Easy Light-Dark Mode Color Switching w... by bramus on Tuesday October 10, 2023 @07:19AM (#37830714)
(Hi, author of the post/article here)

Yes, `light-dark()` is very specific in what it can do … but it’s not the end goal. The end goal is to have a generic function – something like `schemed-value()` – that can respond to a plentitude of `color-scheme` values and return more than just `<color>` values.

Reality is, though, that browsers don’t have support for custom `color-scheme` values (it’s explicitly forbidden in the spec, for now) [^1] and that CSS parsers need to know ahead of time what they are about to parse [^2].

By narrowing things down in feature scope, you can use this convenience method now, instead of needing to wait a few months/years until the rest is figured out.

Once `schemed-value()` becomes a thing, `light-dark()` can become syntactic sugar for it:

``` light-dark(<color>, <color>); = schemed-value(light <color>, dark <color>); ```

[^1]: https://drafts.csswg.org/css-color-adjust/#color-scheme-prop... [^2]: https://www.w3.org/TR/css-syntax-3/#parse-grammar