How to Mix Colors in CSS (and Color Theory)
How CSS color-mix() blends colors, measured: the same blue and yellow give grey in sRGB, a pinkish grey in Lab, teal in OKLCH and spring green in HSL. None of them gives paint-like green, and here is why.
The color-mix() Function
color: color-mix(in oklch, #FF6B6B 60%, #0575E6);
color-mix() (CSS Color Module Level 5) blends two colors in a color space you name; percentages set the share of each, and a missing one takes the remainder. MDN's compatibility data lists it in Chrome and Edge 111, Firefox 113 and Safari 16.2, so every current browser supports it. The color space is not a detail: it decides the result.
Same Two Colors, Six Spaces: Measured
We asked Chromium for a 50/50 mix in each space and read the result back as sRGB (October 14, 2026; script in our test folder):
| Space | blue + yellow | #FF6B6B + #0575E6 | red + lime |
|---|---|---|---|
| srgb | #808080 | #8270a8 | #808000 |
| srgb-linear | #bcbcbc | #bc70b6 | #bcbc00 |
| lab | #c289ac | #b373a9 | #c8ac00 |
| oklab | #6cabc7 | #a17daf | #d0a800 |
| oklch | #00cfbd | #bc60d3 | #f99500 |
| hsl | #00ff80 | #c92efd | #ffff00 |
Rectangular spaces (srgb, lab, oklab) average the coordinates, so opposite colors meet in the grey middle: blue and yellow give exactly #808080 in sRGB. Linear-light sRGB keeps the mix bright, closer to what blending light does. Polar spaces (oklch, hsl) go round the hue circle the shorter way and keep saturation, so blue and yellow become teal in oklch and spring green in hsl, and red with lime gives a vivid orange instead of olive.
No setting reproduces paint, where blue and yellow pigments make green, because pigments subtract light and screens add it. Pick the space for the result you want: oklab for even, natural-looking steps between two colors, oklch when you want to keep colors saturated through the middle, srgb only when you need to match older tools.
Practical Uses
- Tints and shades:
color-mix(in oklab, var(--brand), white 20%)andโฆ, black 20%). - Hover states that follow a theme variable without a second hard-coded color.
- Transparent variants:
color-mix(in srgb, var(--brand) 40%, transparent). - Check contrast after mixing: a tint of a passing color may no longer pass on white.
The Color Mixer blends two colors in sRGB, linear sRGB, OKLab, OKLCH or HSL at any ratio and copies both the hex value and the matching color-mix() expression; its results match Chrome's own color-mix() to within half a step of 255.