brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: light-dark() in css picks a color for the light or dark scheme in one value

Css
~/tips/tip-css-light-dark-color-function

:root { color-scheme: light dark; }

Chooses between a light and a dark color value without a separate media query block.

Dark mode does not need a second block of overrides for every color.

:root { color-scheme: light dark; }
body { color: light-dark(#1f2328, #e6edf3); background: light-dark(#ffffff, #0d1117); }

light-dark(a, b) returns the first color in a light scheme and the second in a dark scheme, following the visitor’s system setting. It only responds when color-scheme is set to light dark on the element or an ancestor, which is why the first line is there. I use it for colors, and when a theme changes many other values at once, a prefers-color-scheme media query is still the better tool. MDN lists it as widely available since May 2024.

Further reading: MDN: light-dark()

More Css tips CSS Overview in Chrome DevTools audits the colors and fonts of a page .notice:empty { .toast { article { counter-reset: h2; } .toolbar { All Css tips (66) All topics

Link