CSS Function
light-dark()
The light-dark() function returns one of two colors depending on the element's computed color-scheme (light or dark).
Syntax
light-dark(light-color, dark-color)Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| light-color | color | Yes | Color to use in light mode |
| dark-color | color | Yes | Color to use in dark mode |
Examples
Text color toggle
Dark text in light mode, light text in dark mode.
css
color: light-dark(#1a1a1a, #f5f5f5);Background toggle
Requires color-scheme to be set.
css
:root { color-scheme: light dark; }
body { background: light-dark(white, #121212); }With oklch colors
Using modern color functions inside light-dark().
css
color: light-dark(oklch(0.3 0.1 250), oklch(0.9 0.05 250));Browser Support
✓
Chrome
v123++
✓
Firefox
v120++
✓
Safari
v17.5++
✓
Edge
v123++
✓
Opera
v109++
Tailwind Equivalent
You can achieve similar results in Tailwind CSS using the following utility classes:
Tailwind uses dark: variant instead: text-gray-900 dark:text-gray-100Frequently Asked Questions
Does light-dark() require prefers-color-scheme?▼
No. It depends on the computed color-scheme property, not the media query. You must set color-scheme: light dark on a parent element.
Can I nest light-dark() in other color functions?▼
Yes. light-dark() returns a color value and can be used anywhere a color is accepted, including inside color-mix().
Explore CSS Color Tools
Try our free tools to work with light-dark() and other CSS color functions.
Open Tools