CSS light-dark() Function
- Previous Page CSS lch() function
- Next Page CSS linear-gradient() function
- Go to Parent Level CSS Function Reference Manual
Definition and Usage
CSS's light-dark()
function allows setting two color values, if the user sets a light theme, it returns the first value; if the user sets a dark theme, it returns the second value.
To use light-dark()
function, CSS's color-scheme
The property must be set to light dark.
Tip:Users can specify their color scheme preference through operating system settings (light or dark mode) or browser settings.
Example
Usage light-dark()
The function enables two color value settings:
:root { color-scheme: light dark; --light-bg: snow; --light-color: black; --dark-bg: black; --dark-color: snow; } * { background-color: light-dark(var(--light-bg), var(--dark-bg)); color: light-dark(var(--light-color), var(--dark-color)); }
CSS Syntax
light-dark(lightcolor, darkcolor)
Value | Description |
---|---|
lightcolor | Required. Specifies the color value for the light theme. |
darkcolor | Required. Specifies the color value for the dark theme. |
Technical Details
Version: | CSS Color Module Level 5 |
---|
Browser Support
The numbers in the table represent the browser version that first fully supports this function.
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
123 | 123 | 120 | 17.5 | 109 |
Related Pages
Reference:CSS color-scheme property
Reference:CSS var() function
Tutorial:CSS Variables
- Previous Page CSS lch() function
- Next Page CSS linear-gradient() function
- Go to Parent Level CSS Function Reference Manual