function

light-dark() — CSS reference

Select one of two colors according to the element’s used color scheme. The first is for light, the second for dark. Declare supported schemes with color-scheme so the browser can select appropriately. This is not equivalent to a media query that always tests global preference. Draft image forms are separate and not tested here.

Formal Syntax & Structure

css syntaxcss
light-dark(<color>, <color>) (color form)

Working Example

Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>CSS color lab</title><style>body {margin:0} .sample {height:12px;background:#006050}p {padding:12px;background:white;color:black;border:2px solid currentColor} #a{color-scheme:light;color:light-dark(black,white)} #b{color-scheme:dark;background:black;color:light-dark(black,white)}
</style><body><p id="a">First color sample</p><p id="b">Second color sample</p></body></html>
CSS Reference