Market
Pricing
Sign inStart
Field GuideCSS and web
CSS and web

color-mix() in CSS: blending colours in the browser

color-mix() lets the browser do the colour maths you used to do in a preprocessor or by eye. Pick the right colour space and one brand colour can produce a whole palette of tints, shades and translucent versions.

GradientlyVerified Gradiently account·October 1, 2026·5 min read
Cover: Rain Rampart · GR·A80B·X7

The short version

  • The color-mix CSS function blends two colours in a named colour space, for example color-mix(in oklab, #7c3aed 40%, white).
  • If you give only one percentage, the other colour gets the remainder; with none, the mix is half and half.
  • Mixing in oklab keeps lightness even and avoids the grey middles that sRGB mixing produces between distant hues.
  • Mixing a colour with transparent is the cleanest way to make a translucent version of a colour stored in a custom property.
  • color-mix() works in all current major browsers, so it is safe for production with a plain colour as a fallback for very old ones.
On this page
color-mix() syntaxWhich colour space to mix inTints and shades from one brand colourTransparency with color-mix()Common color-mix() mistakesBrowser support and fallbacksMixing colours for gradients

The color-mix CSS function, color-mix(), blends two colours in a colour space you choose and returns a new colour. Write color-mix(in oklab, #7c3aed 40%, white) and you get a pale violet that is 40 percent violet and 60 percent white, mixed perceptually. It works in every current major browser. Paired with custom properties, it turns one brand colour into tints, shades, hover states and translucent overlays without a single hard coded hex.

color-mix() syntax

css
/* color-mix(in <colour space>, <colour> [<percentage>], <colour> [<percentage>]) */

.a { color: color-mix(in oklab, #7c3aed, white); }          /* 50% each */
.b { color: color-mix(in oklab, #7c3aed 40%, white); }      /* 40% violet, 60% white */
.c { color: color-mix(in oklab, #7c3aed, black 30%); }      /* 70% violet, 30% black */
.d { color: color-mix(in srgb, #7c3aed 50%, transparent); } /* violet at half opacity */
.e { color: color-mix(in oklch shorter hue, #2563eb, #f59e0b); }
The colour space comes first and is written out. Hue based spaces such as oklch and hsl also accept a hue direction: shorter, longer, increasing or decreasing.
No percentages

Browser uses

50% and 50%

Notes

An even mix
One percentage, say 30%

Browser uses

30% and 70%

Notes

The other colour gets the remainder
Two that add to 100%

Browser uses

As written

Notes

The clearest form to read later
Two that add to more than 100%

Browser uses

Scaled down to 100%

Notes

60% and 60% behaves like 50% and 50%
Two that add to less than 100%

Browser uses

Scaled up, then made translucent

Notes

20% and 30% gives a half opacity result
You writeBrowser usesNotes
No percentages50% and 50%An even mix
One percentage, say 30%30% and 70%The other colour gets the remainder
Two that add to 100%As writtenThe clearest form to read later
Two that add to more than 100%Scaled down to 100%60% and 60% behaves like 50% and 50%
Two that add to less than 100%Scaled up, then made translucent20% and 30% gives a half opacity result
How percentages resolve. The last row surprises people: an under 100 total makes the result partly transparent.

Which colour space to mix in

The colour space decides the path between the two colours. In sRGB the browser averages red, green and blue numbers, which is fast to reason about but not how eyes see. Two distant hues pass through a dull grey on the way. In oklab the mix follows perceived lightness and colour, so the middle stays clean and the steps look even. Gradient interpolation explains the same choice for gradients, and the effect is easiest to see there.

Blue to yellow in three spaces. The midpoint of each strip is exactly what color-mix() returns at 50 percent in that space: #808080 in sRGB, a light blue grey in oklab.
  • oklab for tints, shades and most everyday mixing. Even lightness, no grey dip.
  • oklch when you want the hue to travel, for example blending two brand colours into a third that sits between them on the wheel.
  • srgb for mixing with transparent or matching older design tools that blend in sRGB.
  • srgb-linear for physically based light mixing, which reads brighter in the middle.

For the background on why perceptual spaces behave better, see OKLCH explained. Recent versions of the specification allow you to leave the colour space out and default to oklab, but support for that shorthand is newer, so write in oklab explicitly.

Tints and shades from one brand colour

The most useful pattern is a scale built from a single variable. Mix towards white for tints, towards black for shades. Change the variable and every step updates, which makes it ideal for multi brand products or themes chosen by the user.

css
:root {
  --brand: #7c3aed;

  --brand-100: color-mix(in oklab, var(--brand) 20%, white);
  --brand-200: color-mix(in oklab, var(--brand) 40%, white);
  --brand-300: color-mix(in oklab, var(--brand) 60%, white);
  --brand-400: color-mix(in oklab, var(--brand) 80%, white);
  --brand-500: var(--brand);
  --brand-600: color-mix(in oklab, var(--brand) 80%, black);
  --brand-700: color-mix(in oklab, var(--brand) 60%, black);
}
A seven step scale from one colour. Swap --brand for any hex and the scale follows.
What the scale above resolves to for #7c3aed, computed in oklab. Mixed in sRGB, the tints come out a little greyer and the shades a little flatter.

Mixing with pure white and black is a starting point. For warmer tints, mix towards an off white such as #fdf6ec; for richer shades, mix towards a deep navy instead of black. That keeps the scale feeling like your brand rather than a generic ramp. Tints, tones and shades covers the colour theory.

Transparency with color-mix()

Before color-mix(), making a translucent version of a colour stored in a variable meant storing the channels separately. Now you mix with transparent. The amount you keep is the opacity.

css
.badge {
  color: var(--brand);
  background: color-mix(in srgb, var(--brand) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--brand) 30%, transparent);
}

.button:hover {
  background: color-mix(in oklab, var(--brand), black 12%);
}
A tinted badge and a hover state from the same variable. No second colour to maintain.

Common color-mix() mistakes

  • Leaving out the colour space in code that must run in older browsers. The whole declaration is dropped, not just the space.
  • Mixing with black for every shade. Shades of saturated colours go dull; mix towards a deep version of the hue instead.
  • Expecting percentages under 100 to stay opaque. color-mix(in oklab, red 20%, blue 30%) is half transparent.
  • Using hsl for tints. Lightness in hsl is not perceptual, so a yellow and a blue at the same mix look nothing like the same step.

Browser support and fallbacks

color-mix() has been available in Chrome, Edge, Firefox and Safari since 2023, and current support is listed on caniuse. If you need to cover very old browsers, declare a plain colour first and let the mixed one override it. Browsers that don't understand the second line ignore it.

css
.card {
  background: #ede9fe;
  background: color-mix(in oklab, var(--brand) 15%, white);
}
Fallback first, enhancement second. The cascade does the rest.

A full theme built on these patterns, with light and dark modes, is in CSS variables for theming.

Mixing colours for gradients

color-mix() is handy inside gradients, where it can compute a middle stop from two brand colours so the blend never passes through mud. linear-gradient(135deg, var(--a), color-mix(in oklch, var(--a), var(--b)), var(--b)) gives you a third stop on the hue path between the two. The underlying problem is covered in muddy gradients.

If your brand colour lives in a Gradiently Mark, the Mark's recipe already holds a family of related colours chosen to work together, and the Market lets you search by colour words such as "deep violet" to find one built around the hue you start from.

Find a gradient that’s only yours

Browse thousands of Marks, design with any of them for free, and claim the one that feels like you.

Browse the Market

Questions people ask

What does color-mix() do in CSS?

It blends two colours in a colour space you name and returns the result, for example color-mix(in oklab, red 30%, white).

Which colour space should I use with color-mix()?

Use oklab for tints, shades and most mixing, oklch when you want the hue to travel, and srgb for mixing with transparent.

How do I make a colour transparent with color-mix()?

Mix it with transparent: color-mix(in srgb, var(--brand) 20%, transparent) gives the brand colour at 20 percent opacity.

Is color-mix() supported in all browsers?

It works in current versions of Chrome, Edge, Firefox and Safari. Declare a plain colour first as a fallback for older browsers.

What happens if the percentages don't add up to 100?

Totals above 100 are scaled down. Totals below 100 are scaled up and the result becomes partly transparent.

Share this guide

Written by GradientlyVerified Gradiently account

The team behind Gradiently, a design tool built around Marks: living gradients that make everything you design look like yours.

See our profile

On this page

color-mix() syntaxWhich colour space to mix inTints and shades from one brand colourTransparency with color-mix()Common color-mix() mistakesBrowser support and fallbacksMixing colours for gradients

Share this guide

Next in CSS and web

Build a CSS variables theme: light, dark and brand colours

Keep reading

All CSS and web guides
CSS and web

Build a CSS variables theme: light, dark and brand colours

5 min read

Themes go wrong when colours are named for what they look like instead of what they do. Name the roles, point them at a palette, and light mode, dark mode and a second brand become a few lines each.

Colour

OKLCH explained: perceptual colour for designers

5 min read

HSL promised readable colour and nearly delivered. OKLCH keeps the readable part and fixes the lie about lightness, which is why design systems are moving to it.

Gradients

Gradient interpolation: sRGB, OKLab and why it matters

5 min read

Pick blue and yellow, blend them, and the middle turns grey. That is not your colours failing. It is the maths of the colour space doing the blending, and since CSS Color 4 you can change it.

Find the look that’s only yours.

Every Mark is a living background with one owner. Try an unclaimed Mark, and claim yours when it feels right.

Start designing

Check a certificate

Type a certificate number or a Mark’s code to see who owns it.

Works with ChatGPT and Claude

Ask your AI for a design. It makes it in your Mark, ready to edit.

ChatGPTClaude
How to connect

Product

  • Market
  • Explore
  • Pricing
  • Certificates

Learn

  • Field Guide
  • Help centre
  • What’s new

Developers

  • Overview
  • ChatGPT and Claude
  • API reference
  • API keys

Company

  • About
  • Contact us
  • Sign in

Legal

  • Terms
  • Privacy
  • Refunds
  • Mark protection
  • Cookies
  • All policies
Move through the letters. Each one wears a real Mark.Touch a letter to see its Mark.One name. Ten Marks inside it.
© 2026 Gradiently