color-mix()
When to Use
Use
color-mix()to mix two colors natively — the direct replacement for Sasslighten(),darken(), andmix(). Always specifyin oklchfor perceptually uniform results; usein srgbonly when mixing withtransparent.
Decision
| If you need... | Use... | Example |
|---|---|---|
| Lighter tint of a brand color | Mix with white in oklch |
color-mix(in oklch, var(--brand) 70%, white) |
| Semi-transparent overlay | Mix with transparent in srgb |
color-mix(in srgb, var(--brand) 20%, transparent) |
| Mid-point between two colors | 50% mix | color-mix(in oklch, red 50%, blue) |
| Darkened shade | Mix with black | color-mix(in oklch, var(--brand) 70%, black) |
Pattern
:root {
--brand: oklch(55% 0.18 250);
/* Tint — like Sass lighten() */
--brand-light: color-mix(in oklch, var(--brand) 60%, white);
/* Shade — like Sass darken() */
--brand-dark: color-mix(in oklch, var(--brand) 70%, black);
/* Semi-transparent — like rgba() but from a token */
--brand-overlay: color-mix(in srgb, var(--brand) 15%, transparent);
/* Mix two brand colors */
--brand-mixed: color-mix(in oklch, var(--primary) 60%, var(--secondary));
}
The percentage is the proportion of the first color. Omitting it defaults to 50%.
Color space matters: in oklch produces perceptually uniform mixing. in srgb produces muddy mid-tones. in hsl has similar perceptual uniformity problems as HSL generally.
Browser support: Chrome 111, Firefox 113, Safari 16.2. Widely available since May 2023. Safe to use.
Common Mistakes
- Wrong: Using
in srgbfor tints and shades → Right:in srgbproduces visually muddy results; usein oklch - Wrong: Expecting
color-mixas a fallback for older browsers → Right: There is no graceful degradation; older browsers get no color; test your fallbacks - Wrong: Mixing with
transparentusingin oklch→ Right: OKLCH transparent has hue artifacts; usein srgbspecifically for transparent mixing