color-mix()
Example
:root {
--brand: #1f5eff;
--brand-light: #8fb0ff;
}:root {
--brand: #1f5eff;
--brand-light: color-mix(in oklab, var(--brand) 50%, white);
}The tint is derived from --brand, so changing the brand color updates its variants too.
Common mistakes
- Reading the percentage as the share of the second color, while it belongs to the color it follows.
- Percentages that add up to less than 100%, which also lowers the alpha.
Key points
- The interpolation space is set as the first argument, often
in oklaborin oklch. - Tints and shades mix a base color with 'white' or 'black' instead of hardcoding extra hex values.
- Transparent variants mix with
transparent, likecolor-mix(in srgb, var(--brand) 40%, transparent).
Interview questions
Which color space should I use in color-mix()?
oklab gives even, natural blends for most UI work. srgb matches many design tools, and oklch keeps the hue but can pass through vivid colors.
Can color-mix() make a color transparent?
Yes. Mix it with transparent, like color-mix(in srgb, red 30%, transparent), to get red at 30% opacity.
What is the difference between color-mix() and relative color syntax?
color-mix() blends two colors. Relative color syntax changes single channels of one color, like its lightness or alpha.