color-mix()
The color-mix() function mixes two colors in a given color space and by a given amount. Commonly, lighter or darker variations of a color are created by mixing with white or black.
Overview
The color-mix() function mixes two colors in a given color space and by a given amount. Commonly, lighter or darker variations of a color are created by mixing with white or black.
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 111 | 111 | 113 | 16.2 | 111 | 16.2 | |
1+Supported (version) Not supported ※Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)
Syntax
CSS
/* Basic blending (sRGB) */
.mixed {
color: color-mix(in srgb, #ff0000, #0000ff);
}
/* Specify percentage */
.light-brand {
background: color-mix(in oklch, var(--brand) 80%, white);
}
/* Adjusting transparency */
.faded {
color: color-mix(in srgb, var(--text-color) 60%, transparent);
}
/* Adjusting brightness on hover */
.button:hover {
background: color-mix(in oklch, var(--btn-bg) 85%, black);
} Live demo
Use cases
Using color-mix()
The color-mix() function mixes two colors in a given color space and by a given amount. Commonly, lighter or darker variations of a color are created by mixing with white or black.
Cautions
- May not be supported in older browsers.
Accessibility
- Make sure visual changes are conveyed appropriately to assistive technology.
Related links
Powered by web-features