# color-mix()

> The `color-mix()` CSS function blends two or more colors together based on a specified weight or ratio.

## How do I mix two colors in CSS with color-mix()?

The function that blends two colors together based on a specified ratio, creating a new color that is a mix of the two. It's useful for generating gradients, adjusting colors dynamically or creating themes with blended hues.

- Topic: Colors
- Type: function
- Browser support: Chrome 111+, Chrome Android 111+, Edge 111+, Firefox 113+, Firefox Android 113+, Safari 16.2+, Safari iOS 16.2+

## Example

Wrong:

```css
:root {
  --brand: #1f5eff;
  --brand-light: #8fb0ff;
}
```

Right:

```css
: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 oklab` or `in oklch`.
- Tints and shades mix a base color with 'white' or 'black' instead of hardcoding extra hex values.
- Transparent variants mix with `transparent`, like `color-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.

## Related cards

- [Relative Colors](https://wonderium.dev/css/relative-colors.md)
- [oklab()](https://wonderium.dev/css/oklab.md)
- [Variables](https://wonderium.dev/css/variables.md)
- [light-dark()](https://wonderium.dev/css/light-dark.md)
- [oklch()](https://wonderium.dev/css/oklch.md)

---

- Level: [CSS](https://wonderium.dev/css.md)
- HTML version: https://wonderium.dev/css/color-mix
- Last updated: 2026-11-25
