CSS color has picked up a lot of new vocabulary alongside its new functions. Guides to the Almanac now cover color(), hsl(), lab(), lch(), oklab(), oklch() and rgb(), and recent additions like contrast-color() and color-mix() make the terminology harder to keep straight. The terms below are a reference for that vocabulary for anyone using functions like lab() or oklch() without necessarily being confident about what distinguishes them.

Where color starts: the CIE experiments

Color is not a physical property of objects. Light is the main cause of color, but a color is perceived only once visible light enters the eye and the brain interprets it. As Elle Stone put it:

Light waves are out there in the world, but color happens in the interaction between light waves and the eye, brain, and mind.

Reproducing color reliably therefore means relating measurable light wavelengths to the responses they produce in viewers. The International Commission on Illumination (CIE, from its French name) did this work 95 years ago, mapping all the colors visible to the average human in its experiment to wavelengths and describing them with only three values.

Those values first corresponded to the red, green and blue wavelengths used in the experiment, forming the CIERGB color space. Because some visible colors required a negative wavelength to represent, a series of transformations produced CIEXYZ instead. In CIEXYZ, X and Z describe chromaticity while Y describes luminance. Slicing the resulting 3D shape at constant luminance gives all visible colors for that luminance in the xy chromaticity diagram:

xy chromaticitydiagram showing all visible colors

Colors inside the shape are considered real; those outside are considered imaginary.

Color spaces

A color space is a general mapping of color into a three-value coordinate system; it does not need to include every visible color. CIEXYZ matters because it maps all colors visible to the average human eye and is useful for defining other color spaces, describing their gamuts and converting between them.

RGB spaces

RGB color spaces need only amounts of red, green and blue. Defining one requires just the "reddest," "greenest" and "bluest" colors. On a 0-to-1 scale, (1, 0, 0) is the reddest color, (0, 1, 0) the greenest and (0, 0, 1) the bluest. What counts as "bluest" is arbitrary on its own, which is why the xy chromaticity diagram is useful: the three primaries can be placed as coordinates inside it, and that is all an RGB color space takes.

Different shades of blue

The most-used space in CSS is standard RGB (sRGB), which leaves many colors out. Newer RGB spaces with more colors are available through the color() function, including display-p3, prophoto-rgb and rec2020.

sRGV and WideGamutRGB in the xy chromaticity diagram
Credit: Elle Stone

ProPhoto RGB extends outside the visible colors. That is fine: colors outside are clamped rather than becoming new or invisible colors.

Comparing the shapes of various color spaces, including sRGB, Display P3, A98-RGB, Rec2020, and ProPhoto.
Credit: Chrome Developer Team

CIELAB and Oklab

sRGB has two problems: it lacks many colors the eye can see, and it is not perceptually uniform, so a change in chromaticity also changes perceived lightness. CIELAB, created by the CIE in 1976 and derived from CIEXYZ, encompasses all visible colors with three coordinates: L* for perceptual lightness, a* for red-green and b* for yellow-blue.

A diagram in the shape of a sphere containing a range of colors that go from white to black vertically and green to blue to yellow to red horizontally.
Credit: Linshang Technology

CIELAB is far more perceptually uniform than sRGB but not completely so, especially in gradients involving blue; a white-to-blue CIELAB gradient shifts toward purple.

Comparing blue gradients in Oklahoma and CIELAB. The CIELAB gradients contains shades of purple.
Image Credits to Björn Ottosson

Björn Ottosson's Oklab also holds all visible colors while improving perceptual uniformity, using the same L*a*b* coordinates.

Models and gamuts are not spaces

A color model is a mathematical description of color as tuples of numbers. On its own it does not specify a color until paired with a color space. In the RGB model a color is three values, but it only becomes a color once matched to an RGB space. One space can offer several models (sRGB uses RGB, HSL and HWB), and one model can appear in several spaces.

Definitions vary in practice. Chrome's High definition CSS color guide describes CSS's RGB and HSL as different color spaces, while MDN's Color Space entry treats RGB and HSL as part of the sRGB color space. For CSS, treating RGB, HSL and HWB as different models for accessing sRGB is easier to work with.

A color gamut is the range of colors available in a color space, so saying one space has "more colors" than another really means a wider gamut. Gamuts are also limited physically: an older screen may not display every color a space offers. A color that cannot be represented, whether because it falls outside the space or because of a display limitation, is out of gamut.

Which CSS function reaches which space

  • sRGB: hexadecimal notation, named colors, rgb(), rgba(), hsl(), hsla() and hwb().
  • CIELAB: lab() for Cartesian coordinates and lch() for polar coordinates.
  • Oklab: oklab() for Cartesian coordinates and oklch() for polar coordinates.
  • Beyond these: color() and color-mix() reach the RGB spaces rgb-linear, display-p3, a98-rgb, prophoto-rgb and rec2020, plus the XYZ spaces xyz, xyz-d50 and xyz-d65.

Quick reference

  1. Color spaces map available colors onto a coordinate system. CSS has three main ones (sRGB, CIELAB, Oklab), with many more through color().
  2. Color models define color as numeric tuples but carry no actual color until paired with a space; the RGB model means nothing without an RGB space.
  3. Color gamut is the term for how many colors a space holds, and it is tied to the physical limits of cameras and displays. A color that can't be represented is out of gamut.
  4. Color functions are how CSS reaches all of these spaces.
  5. CIEXYZ underpins the definition of other color spaces, the description of their gamuts and conversion between them.