On this page
light-dark()
Prev: `color-mix()` | Up: color | Next: `linear-gradient()`
Rel: color, Color & Value Functions Guide
Ref: MDN Web Docs — light-dark()
Tags: #public #web #css #functions #color #tier/core
Syntax & Overview
light-dark(#ffffff, #141619)
Returns the first color in light color-scheme and the second in dark color-scheme.
Notes & Best Practices
- Requires
color-scheme: light darkon:root(or an ancestor): Withoutcolor-scheme,light-dark()always picks the light value. - Eliminates duplicate
@media (prefers-color-scheme: dark)blocks for color tokens.
Example
:root {
color-scheme: light dark;
--surface: light-dark(#ffffff, #14161a);
--ink: light-dark(#1a1d21, #e8ecf2);
}
body { background: var(--surface); color: var(--ink); }
Linked from
Related notes
- tuts/css/functions/color/color-mix Linked here; links to this page; shared tags: #color, #css, #functions, #tier, #web
- tuts/css/functions/color/linear-gradient Linked here; links to this page; shared tags: #color, #css, #functions, #tier, #web
- tuts/css/functions/color Linked here; links to this page; shared tags: #color, #css, #functions, #web
- tuts/css/functions/color_and_value_functions Linked here; shared tags: #color, #css, #functions, #web
- tuts/css/functions/color/oklch shared tags: #color, #css, #functions, #tier, #web
- tuts/css/functions/color/var shared tags: #color, #css, #functions, #tier, #web
- tuts/css/functions/math/calc shared tags: #css, #functions, #tier, #web
- tuts/css/functions/math/clamp shared tags: #css, #functions, #tier, #web
- tuts/css/functions/math/min shared tags: #css, #functions, #tier, #web
- tuts/css/functions/math/minmax shared tags: #css, #functions, #tier, #web