r/css • u/fdiengdoh • 7d ago
No AI used light-dark ()
Why didn’t I know about this earlier. It’s such a nice way to achieve light/dark mode.
I just re-build my link list site using this function. Also generated color schemes at colorffy.
5
Upvotes
4
u/DHTechdev 6d ago
One thing that trips people up: light-dark() only works once you set color-scheme: light dark on :root (or the element). Without it the function always returns the light value.
5
u/minmidmax 7d ago
Modern CSS has a lot of stuff that makes historic bullshit redundant. It's amazing these days.
3
u/fishpowered 5d ago
in addition: color-contrast() css func has pretty good support. also some ppl make their css classes in terms of prominence (instead of light to dark) and use opacity to make them more or less prominent in whichever light/dark mode u are in
1
u/testingaurora 2d ago
Something I misunderstood is that it can only work with colour values.
For instance I cannot set `animation-duration; light-dark(400ms, 1000ms);` or `—elevation: light-dark(1,0)`
I believe the plan is eventually to worth with other types. But yeah it’s amazing even with only colours. Cut my framework in half.