Encodera

Thanks for reading!

Donate to the site — we work hard for you.

HTML & CSS reference

color-mix()

Mixes two colors in the given proportion.

Syntax

color-mix(in space, color1 p%, color2)

Parameters

ParameterTypeDescription
in spacecolor spaceThe color space for mixing: `in oklch`, `in srgb`.
color p%colorColors with optional percentages; by default 50% each.

Examples

A darker hover state and a light tint from one brand color:

<style>
  :root { --brand: royalblue; }
  .btn { padding: 8px 16px; border: 0; color: white; background: var(--brand); }
  .btn:hover { background: color-mix(in oklch, var(--brand), black 25%); }
  .soft { background: color-mix(in oklch, var(--brand) 20%, white); color: black; }
</style>
 
<button class="btn">Hover — darker</button>
<button class="btn soft">A light tint</button>

Notes

With color-mix() one variable is enough for a whole palette of shades. Mixing in oklch usually gives more natural results than in srgb. Supported in all current browsers since 2023.

See also

  • oklch() — A color in the OKLCH space: perceived lightness, chroma and hue.
  • var() — Inserts the value of a custom property (a CSS variable).
  • color — The color of the text (and the default color of borders and SVG icons).

Related recipes

In the tutorial

  • Modern colors — The oklch() function and why it makes palettes easy, mixing colors with color-mix() and the relative syntax oklch(from ...).

Thanks for reading!

Donate to the site — we work hard for you.