Color and Color Spaces in CSS
Learn CSS color values and color spaces, from named and sRGB colors through wide-gamut spaces, alpha, currentColor, interpolation, gamut mapping, and developing Color 5 features without duplicating other CSS owners.
Basic
CSS color is a value system, not just a collection of familiar swatches. The Color specifications define how CSS represents colors, how those colors are converted between supported spaces, how alpha participates in a color, and how colors are interpolated and gamut-mapped. This lesson is the primary owner for those color concepts.
This lesson deliberately does not become a background, border, shadow, compositing, accessibility-guideline, or user-preference lesson. Background and border painting belong to Backgrounds and Borders; detailed compositing and blending belong to the Masking, Clipping, Compositing, and Blending owner; user color preferences belong to Color Adjustment and responsive media-query work.
A color is a value, not a decoration
The color value can be used anywhere a property accepts <color>. The same value can describe text, a border, a background, or another color-bearing property. The property decides what is painted; the Color module defines the color value itself.
|
|
Do not confuse the property with the color. color is a CSS property. rebeccapurple, rgb(...), and oklch(...) are color values.
Output
Ready to run.
Quick check
Which part is the color value in `color: oklch(60% 0.15 250)`?
Named and hexadecimal colors
Named colors are predefined keywords. Hexadecimal notation represents sRGB channel values compactly, with three-, four-, six-, or eight-digit forms. An eight-digit form includes an alpha component.
|
|
Hex notation is useful when you want a compact sRGB representation. It is not a separate color space from sRGB; it is another syntax for specifying sRGB components.
Output
Ready to run.
Quick check
What color space do ordinary hexadecimal CSS colors represent?
rgb() describes sRGB channels
The modern rgb() syntax accepts numeric or percentage channel values and an optional alpha after a slash. The space-separated form is the current syntax used throughout the Color specifications.
|
|
Output
Ready to run.
Quick check
Where is alpha written in modern `rgb()` syntax?
hsl() changes how you reason about sRGB colors
hsl() expresses an sRGB color using hue, saturation, and lightness. It is a different coordinate system for the same sRGB color model, not a claim that every equal lightness number looks equally bright to human observers.
|
|
HSL is useful when you want to reason about hue, saturation, and lightness. Its lightness value should not be treated as a perceptual-lightness guarantee.
Quick check
What is the safest description of HSL?
Wide-gamut and perceptual spaces
CSS Color 4 adds color spaces beyond the narrow sRGB gamut, including Display-P3 and the Lab/LCH and OKLab/OKLCH families. These spaces let CSS represent colors and reason about them in ways that are not limited to sRGB coordinates.
|
|
Output
Ready to run.
Quick check
Why is OKLCH not simply another spelling of hex?
Lightness is not the same thing in every space
A percentage called lightness does not carry one universal meaning across CSS color spaces. HSL lightness is defined within HSL; Lab and OKLab have their own lightness dimensions. Compare values within their model instead of assuming that 50% in every function means the same visual result.
Output
Ready to run.
Quick check
Can you assume `50%` lightness means the same color brightness in HSL and OKLCH?
Alpha is part of a color value
Many CSS color functions accept an optional alpha component. Alpha expresses how much of the color contributes through transparency; it does not create a second color space. The exact visible result also depends on what the color is composited with, which belongs to the compositing model.
|
|
Output
Ready to run.
Quick check
What does changing alpha primarily change?
Current color can be inherited
The currentColor keyword resolves to the element’s computed color value. It is useful when an outline, border, icon, or other color-bearing property should follow the text color without repeating the same literal color.
|
|
Output
Ready to run.
Quick check
What does `currentColor` refer to?
System colors are semantic color values
CSS also defines system color keywords such as Canvas and CanvasText. These represent user-agent or platform semantic colors rather than author-chosen RGB coordinates. They are useful when the intent is to participate in the user agent’s color conventions.
|
|
Output
Ready to run.
Quick check
What is special about a CSS system color such as `CanvasText`?
Interpolation can happen in a chosen color space
CSS Color defines interpolation rules for colors. The interpolation color space matters: a transition between two colors can follow different paths when interpolated in sRGB, Lab, OKLab, or another supported space. Hue interpolation also has defined methods in polar spaces.
Output
Ready to run.
Quick check
Why can interpolation space matter?
Gamut mapping keeps requested colors usable
A color space can describe colors that a particular output gamut cannot reproduce. CSS Color defines gamut mapping so an out-of-gamut color can be mapped toward a displayable result. This is different from simply clipping every channel independently.
|
|
When a color is outside the target gamut, the browser may need to map it. Do not assume that the serialized CSS value and the final displayed color are identical numeric coordinates.
Quick check
What is gamut mapping for?
Color 5 adds newer color tools
CSS Color 5 extends the color model with features including color modification functions, custom color spaces, contrast-color(), light-dark(), and device-cmyk(). These features are current Working Draft material, so treat them as developing rather than as interchangeable with the stable fundamentals.
|
|
For curriculum purposes, learn the stable Color 4 model first. Use Color 5 features when you need them, and label their specification status clearly because the draft can change.
Output
Ready to run.
Quick check
How should a learner treat CSS Color 5 features such as `light-dark()`?
Color is not the same as color adjustment
A page’s preferred light or dark scheme, forced colors, and print color adjustment are defined by CSS Color Adjustment and media-query specifications. They are related to color, but they are not the core color-value model taught here. This boundary keeps the Color lesson focused and prevents repetition later.
|
|
Likewise, contrast requirements from accessibility guidelines are not replaced by choosing a particular color function. A color space can help you reason about colors, but accessibility conformance remains its own standards problem.
A practical color-debugging method
When a color looks wrong, first identify the property and exact color value. Then identify the color space. Check alpha and what is behind the color. If the color is wide-gamut or otherwise outside the output gamut, consider gamut mapping. Finally check whether another mechanism—such as user color adjustment—is affecting the result.
Output
Ready to run.
Quick check
When a color unexpectedly looks different from its CSS number, which investigation is most useful first?
The important ownership boundaries
Color owns the representation and processing of CSS colors. Values & Units owns general value grammar and units. Backgrounds and Borders owns where backgrounds and borders are painted. The Masking, Clipping, Compositing, and Blending lesson owns detailed compositing and blend modes. Color Adjustment and Media Queries own user preferences such as preferred schemes and forced colors. Keep these mechanisms connected in examples without making them competing lesson owners.
Stable versus developing color features
CSS Color Level 4 is a current CSSWG Editor’s Draft dated 30 September 2026. Color Level 5 is separate current draft work. The curriculum therefore keeps the Color 4 model as the foundation while labeling newer Color 5 capabilities as developing instead of presenting them as frozen fundamentals.
Quick review
You should now be able to distinguish color values from the properties that use them, choose an appropriate color notation, recognize the difference between sRGB and newer color spaces, reason about alpha and currentColor, understand interpolation and gamut mapping at a conceptual level, and keep Color 5 and Color Adjustment features in their proper ownership boundaries.
Thanks for your feedback.
Mark this learning resource complete to track your learning progress.