The color-mix() function blends two colors in a chosen color space and returns the result. You write color-mix(in oklab, red 30%, blue) and the browser mixes 30% red with 70% blue. It lets you make tints, shades and hover colors from one base color in plain CSS, without a preprocessor, and css color-mix is supported in current versions of all major browsers.
The syntax is color-mix(in <color-space>, <color> <percentage>?, <color> <percentage>?). This guide covers the arguments, how percentages work, how to pick a color space, and practical patterns.
The first argument chooses the interpolation space after the word in. The next two arguments are the colors, each with an optional percentage.
Any CSS color works as an input: names, hex, rgb(), hsl(), oklch(), currentcolor and custom properties. The result is a normal color, so you can use it in background, border-color, box-shadow and so on.
The percentages describe how much of each color goes into the result:
| Written | Result |
|---|---|
| No percentages | 50% and 50% |
One percentage, for example 30% | That color gets 30%, the other gets 70% |
| Both, adding up to 100% | Used as written |
| Both, adding up to less than 100% | Scaled up to 100%, but the result becomes partly transparent |
| Both, adding up to more than 100% | Scaled down to 100% |
| Both 0% | Invalid |
The transparency rule matters: color-mix(in srgb, red 20%, blue 20%) is the same mix as 50 and 50, but with alpha 0.4. This is useful for transparent versions of a color, and surprising when it happens by accident.
The space decides how the mix looks, because colors are blended channel by channel in that space.
Rules of thumb:
srgb matches what older tools and sass mix() do. Use it when you must match existing colors.oklab is a good default for lightening, darkening and general blending because it is perceptually uniform.oklch and other polar spaces such as hsl keep the colorfulness, but they also blend the hue angle. You can control the path with shorter hue, longer hue, increasing hue or decreasing hue after the space name.One custom property now drives the hover, active and soft variants. If the brand color changes, all of them update.
Mixing with transparent gives an alpha version of any color, including currentcolor:
The outline always matches the text color, at 40% strength. Using in srgb with transparent avoids color shifts that can happen in other spaces.
You can mix against the page colors to keep contrast consistent:
The card is always slightly different from the page surface, in both themes. light-dark() is a separate function that works with color-scheme.
You get a five-step ramp from one value. Check text contrast for each step, because mixing does not guarantee accessible combinations.
color-mix() is a computed-value function, so it works inside custom properties and calc()-free contexts, but it cannot be animated differently from other colors. Very old browsers ignore it, so declare a plain color first:
Use oklab for most tints and shades, and srgb when you must match older tools. Choose oklch when you want to keep colorfulness.
Not in one call. You can nest calls: color-mix(in oklab, color-mix(in oklab, red, blue), green).
color-mix() creates a new color value. opacity makes the whole element see-through. Mixing with transparent gives you a see-through color without affecting the content.
Yes. Custom properties can hold the inputs, and the function resolves when the value is used.
color-mix() blends two colors in a space you choose, with percentages that control the share of each. Use oklab for natural tints and shades, srgb for compatibility and oklch for hue paths. Drive hover states, soft backgrounds and focus rings from one base color, add a fallback line for older browsers and verify text contrast after mixing.