CSS color-mix() Function

The CSS color-mix() function takes two colors and blends them together in a specified color space by a given percentage.

Introduced in CSS Color Module Level 5, color-mix() enables native color manipulation directly within CSS without requiring preprocessors like Sass or JavaScript calculation libraries. It is commonly used to generate hover and active states, create tints and shades, produce semi-transparent color variations, and build adaptive theme palettes.

Syntax

The color-mix() function requires an interpolation color space preceded by the in keyword, followed by two colors with optional percentage weightings:

Parameters

How Percentages Work

You can control the proportion of each color in several convenient ways:

Basic Examples

Here are some examples that demonstrate how to use color-mix():

Using color-mix() in Style Sheets

The CSS specifications state that you can use color-mix() wherever a CSS <color> value is accepted. For example, you can use color-mix() to set the colors of text, backgrounds, and borders:

Choosing an Interpolation Color Space

The color space chosen for mixing has a noticeable impact on the resulting color:

Color Space Characteristics Suitable For
in oklch Perceptually uniform cylindrical space; preserves perceived lightness and vibrancy without producing muddy desaturated midpoints. General UI styling, design tokens, and tint/shade generation (recommended default).
in oklab Perceptually uniform rectangular space; linear transitions between opposing colors without hue curvature. Smooth color gradients and transitions.
in srgb Standard RGB color space. Opposite hues (e.g. red and green) can pass through dark or muddy brown/gray midpoints. Simple transparency adjustments with transparent and legacy color compatibility.
in display-p3 Wide-gamut RGB space; prevents gamut clipping when mixing vibrant wide-gamut colors. Rich color blending on modern high-gamut displays.

Hue Interpolation Modes

When mixing in a polar/cylindrical space like oklch or hsl, colors are situated on a circle (from 0° to 360°). You can explicitly specify how the mix travels between the two hues:

Related Color Functions