CSS Color Functions Reference

rgb(), hsl(), oklch(), color-mix() and all CSS color functions with syntax.

Searchable CSS color function reference covering all Level 4 and 5 color functions — rgb, hsl, hwb, lab, lch, oklab, oklch, color, color-mix, relative color and light-dark — with color space and gamut notes.

Why prefer oklch() over hsl()?

Oklch is perceptually uniform, so equal numeric steps in lightness or chroma look equally different to the eye. HSL is tied to sRGB and its lightness is uneven across hues, which makes gradients and lightness ramps look muddy. Oklch also reaches wide-gamut colors.

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 plagues hsl() 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() requires color-scheme to be declared on the element or root, or it has nothing to switch on.