Colour
light-dark()
Newly availablesince May 2024
Replaces: Every colour declared twice, once inside a prefers-color-scheme block. One declaration carries both values.
See it working
One declaration holds both values. The checkbox only flips color-scheme.
The syntax
:root { color-scheme: light dark; }
.card { background: light-dark(#fff, #14161d);
color: light-dark(#14161d, #f2f3f7); } Edit the demo’s CSS
This is the stylesheet running the demo above. Change a value and watch it. Break it on purpose: delete the modern line and you are looking at the fallback.
For browsers without it
Declare the light value on its own line first. A browser without light-dark() keeps it, and gets a light theme only, which is what it had before.