Modern color spaces
Definition and purpose
CSS can express colors beyond traditional sRGB using functions such as color(display-p3 …), lab(), lch(), oklab() and oklch(). Different spaces use different coordinates and gamuts.
P3 declaration with fallback
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> #a { color: red; color: color(display-p3 1 0 0); } #b { color: red; } </style> </head> <body> <div id="a">Sample A</div> <div id="b">Sample B</div> </body></html>The browser retains P3 notation for A; B is sRGB red.
Syntax and mental model
color(display-p3 1 0 0) specifies P3 red; oklch(60% .15 40) uses lightness, chroma and hue. OKLCH is designed for more perceptually uniform adjustments than HSL. An accepted declaration does not prove the display can reproduce its full gamut. Put a conventional color first as a parsing fallback.
OKLCH chroma
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> #a { color: oklch(0.6 0.15 40); } #b { color: oklch(0.6 0 40); } </style> </head> <body> <div id="a">Sample A</div> <div id="b">Sample B</div> </body></html>Zero chroma makes B neutral, with the same specified lightness.
Common mistakes
Do not assume the same numeric channels represent the same physical color in different spaces. Check gamut and contrast independently.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Contrast and color scheme. Next lesson: Color mixing and relative colors.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Modern color spaces — knowledge check
Five questions on modern color spaces.
What is the first OKLCH component?
What does chroma zero represent?
What does display-p3 identify?
Where should a parsing fallback go?
Does CSS.supports establish physical display gamut?