light-dark() CSS Function
The light-dark() function returns one of two colors, depending on whether the element uses a light or a dark color scheme.
Description
The light-dark() CSS function returns one of two colors depending on whether the element is being displayed with a light or a dark color scheme. It takes two arguments: the first color is used for a light scheme and the second for a dark scheme. This makes it easy to support both light and dark themes from a single declaration, without writing separate @media (prefers-color-scheme: dark) blocks for every color.
For light-dark() to work, the element must have a color-scheme that allows both modes, usually set once on the root with color-scheme: light dark. The browser then follows the user's operating system or browser preference. If color-scheme is set to only light or only dark on part of the page, light-dark() inside that part always picks the matching color, which is a convenient way to force a section into one theme.
:root {
color-scheme: light dark;
}
body {
background-color: light-dark(#ffffff, #0f172a);
color: light-dark(#111827, #e5e7eb);
}
.card {
border: 1px solid light-dark(#e5e7eb, #334155);
}
/* Force one panel to always use the dark colors */
.promo {
color-scheme: dark;
}
light-dark() currently accepts only <color> values. It works well together with custom properties, so you can define a theme once, for example --surface: light-dark(white, black);, and reuse it across a stylesheet.
Interactive Demo
Syntax
light-dark() = light-dark( <color>, <color> )
Values
- light colorThe <color> used when the element's used color scheme is light (or unknown).
- dark colorThe <color> used when the element's used color scheme is dark.
Example
Browser Support
The following information will show you the current browser support for the CSS light-dark() function. Hover over a browser icon to see the version that first introduced support for this CSS function.
Desktop





Tablets & Mobile





