liveBook · Manning

Color interpolation

As explained in CSS in Depth, Second Edition

A color interpolation method specifies how intermediate colors are calculated between color stops.

Color interpolation calculates the intermediate colors between color stops. In CSS gradients, the chosen color space determines the path between those stops; without an explicit choice, interpolation uses sRGB. section 13.1.2

Choose the interpolation space according to the visual transition you want:

  • Use polar spaces such as OKLCH or HSL for gradients between significantly different hues. section 13.1.2
  • Use a rectangular space such as sRGB when fading a vivid color toward gray, black, white, or transparency. section 13.1.2
  • In polar spaces, select the shorter or longer route around the circular hue value; the longer route can create a rainbow. section 13.1.2

Comparing interpolation spaces

A gradient can explicitly request OKLCH interpolation: `linear-gradient(90deg in oklch, yellow, blue)`. Adding `longer hue` makes the interpolation follow the longer path around the hue circle: `linear-gradient(90deg in oklch longer hue, yellow, blue)`.

The same interpolation mathematics applies to `color-mix()`: selecting a percentage along an sRGB gradient is equivalent to mixing those colors in sRGB at that percentage. section 13.1.2

How CSS in Depth, Second Edition covers it

How deep it goes
Explains defaults, color-space trade-offs, and polar hue routes with CSS examples, but stops short of implementation internals.
Examples
Uses yellow-to-blue linear gradients, OKLCH syntax, longer-hue syntax, and comparisons across color spaces.
What you can do after
Evaluate/understand how color-space and hue-route choices change rendered gradients.
How it connects
Connects gradients, color spaces, polar color spaces, and color-mix().

Related concepts

This explainer was generated by Manning's knowledge graph from the text of CSS in Depth, Second Edition. The section links point to the parts of the book it draws on.