Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Functions

The color-mix() function

Reference for the CSS color-mix() function: mix two colors in a chosen color space, set percentages, control hue paths, and build hover shades and tints.

The color-mix() function blends two colors in a color space you name and returns the result as a color. It replaces preprocessor helpers such as mix() and lets you derive hover states, tints and borders from a single brand color at runtime, even when that color comes from a custom property.

CSS
.button {
  background: var(--brand);
}
.button:hover {
  background: color-mix(in oklch, var(--brand), black 20%);
}

Try it

Tints, shades and 50/50 mixes

The same red and blue give different midpoints depending on the space. The last swatch shows a partly transparent red made by mixing with transparent.

Syntax

CSS
color-mix(in <color-space>, <color> [<percentage>], <color> [<percentage>])
color-mix(in <polar-space> [shorter | longer | increasing | decreasing] hue, ...)

Syntax and arguments

Argument Description
in <color-space> The space where mixing happens: srgb, srgb-linear, display-p3, lab, oklab, xyz and others, or a polar one: hsl, hwb, lch, oklch.
hue method For polar spaces only: which way around the wheel the hue travels (shorter is the default).
<color> Any color, including currentcolor, custom properties and system colors.
<percentage> The share of that color. If you give one, the other gets the remainder. If you give none, each is 50%.

If the percentages add up to less than 100%, the result is multiplied by that sum and becomes partly transparent; if they add up to more than 100%, they are scaled down to total 100%.

Usage notes

  • The space matters. srgb mixes can look dull; oklab and oklch usually give the most natural midpoints. Always write the space explicitly.
  • Mixing with black or white. color-mix(in oklab, var(--c), white 30%) gives a tint, and with black a shade, with predictable lightness.
  • Transparency. Mixing with transparent yields translucent versions of a color without needing its channel values.
  • Dynamic. Mixes are computed from the current values of custom properties and currentcolor, so they react to themes.
  • Not animated as a function. Transitions work on the resulting colors; the mixture itself is not interpolated step by step.

Browser support

Supported in current versions of all major browsers. Check a compatibility table for older ones, and put a plain fallback color before the declaration.