CSS

css/light-dark-color-scheme

A project that uses light-dark() declares color-scheme (light dark) on :root or in a meta tag, or the dark values never apply.

moderatestaticfe-css-modern

Why

light-dark(a, b) returns the dark value only when the element's used colour scheme is dark, and that comes from the color-scheme property (or the color-scheme meta tag). Without it the page always shows the light values, whatever the person chose in their system, and form controls and scrollbars stay light too.

Fix

Add color-scheme: light dark; to :root (or <meta name="color-scheme" content="light dark"> in the document head). For a forced theme toggle, set color-scheme: dark or light on the root element from the toggle.

Examples

/* bad */
:root { --bg: light-dark(#fff, #121212); }
/* good */
:root { color-scheme: light dark; --bg: light-dark(#fff, #121212); }

Sources

Facts

Id
css/light-dark-color-scheme
Severity
moderate
Check
static checked in the source by audit
Applies to
project
Taught by the skill
fe-css-modern Modern CSS features
Since version
0.1.0

Rule file on GitHub

Read it in the terminal

npx github:dawidolko/frontend-skills explain css/light-dark-color-scheme