A map of CSS color functions
CSS now offers far more than rgb() and hsl(). The Color Module Levels 4 and 5
add perceptual spaces (lab, lch, oklab, oklch), wide-gamut access via
color(), on-the-fly mixing with color-mix(), relative color syntax and
scheme-aware helpers like light-dark(). This reference lists each function with a
worked example, the color space it lives in and practical notes.
How it works
Every modern color function shares one shape: space-separated channels with an
optional alpha after a slash, for example oklch(0.62 0.18 29 / 0.8). The channels
differ per space. Cylindrical functions (hsl, hwb, lch, oklch) take a hue
angle plus two magnitude channels, so changing one channel keeps the perceived hue
stable. Rectangular functions (lab, oklab) use signed a and b axes.
The color() function names an explicit space such as display-p3 or rec2020,
which is how you reach colors outside sRGB. color-mix() interpolates two colors
in a stated space — and the space changes the result, so color-mix(in oklch, …)
and color-mix(in srgb, …) give different midpoints. Type a keyword above to filter
the table to the functions you need.
Tips and gotchas
- Prefer
oklch()for gradients and lightness ramps: equal steps look even, and you avoid the grey dead-zone that plagueshsl()interpolation. - Wide-gamut colors only render on capable displays; always provide an sRGB-safe fallback for older browsers and screens.
- The slash-alpha form replaces the old
rgba()/hsla()aliases, which remain valid but are no longer needed. light-dark()requirescolor-schemeto be declared on the element or root, or it has nothing to switch on.