liveBook · Manning

Color-mix()

As explained in CSS in Depth, Second Edition

color-mix() is a CSS color function that computes an intermediate color by interpolating two colors in a specified color space.

color-mix() computes an intermediate color by blending two colors in a chosen interpolation color space. It is useful for deriving shades and blended hues without manually calculating new color values. section 11.3.4

The first argument selects the interpolation method, followed by the two colors. For example, color-mix(in oklch, blue, red) produces an intermediate purple. Because color spaces arrange colors differently, the same pair can produce noticeably different results. section 11.3.4

Build a palette from one green

Define a middle color, then derive darker and lighter variants with black and white: --green-30: color-mix(in srgb, var(--middle-green), black 40%); --green-70: color-mix(in srgb, var(--middle-green), white 40%). Percentages skew the result toward the specified color; an omitted percentage receives the remaining share. section 11.3.4

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

  • Use a polar space such as hsl or oklch when blending different hues toward an intermediate hue. section 11.3.4
  • Use srgb when mixing a color with white or black to create lighter or darker shades of that color. section 11.3.4
  • Treat color-mix() as progressive enhancement where necessary: browser support was insufficient in mid-2024 to rely on it without fallback styles. section 11.3.4

How CSS in Depth, Second Edition covers it

How deep it goes
Explains arguments, interpolation spaces, percentages, and practical space selection, but defers detailed gradient interpolation.
Examples
Uses blue-red blending and a stepped green palette mixed with black and white.
What it assumes
Assumes familiarity with CSS colors and custom properties while explaining interpolation methods and mixing percentages.
What you can do after
Build reusable color palettes by mixing CSS colors in selected interpolation spaces and weighting their contributions.
How it connects
Connects color interpolation with color spaces, gradients, custom properties, HSL, and OKLCH.

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.