Mixing and Deriving Colors: color-mix() and Relative Color Syntax
Deriving colors in the browser: color-mix() with color spaces, percentages and transparency, hue interpolation, mixing with currentColor, relative color syntax with from and channel keywords, and building tints, shades and states from one token.
kvi5hnuCode Sprout team member8 min readOn this page
A design system usually needs many versions of each color: lighter tints, darker shades, transparent versions, hover and pressed states. You can define each one by hand, or derive them in CSS from a single base color. Two features do that: color-mix(), which blends colors, and relative color syntax, which takes a color apart and changes its channels.
color-mix()
color-mix() blends two colors in a chosen color space:
.a { background: color-mix(in oklab, #8a3b12, white); } /* half and half */
.b { background: color-mix(in oklab, #8a3b12 70%, white); } /* 70% brand, 30% white */
.c { background: color-mix(in oklab, #8a3b12, black 25%); } /* a 25% darker shade */
in <space>chooses the color space for the mix:srgb,srgb-linear,display-p3,lab,oklab,xyz, the polar spaceshsl,hwb,lchandoklch, and the othercolor()spaces. Leaving it out (defaultoklab) is a recent change, so write the space for now.- Percentages set the proportions. With one, the other color gets the rest. If both are given and add up to more than 100%, they're scaled to 100%.
- If both add up to less than 100%, the result is partly transparent:
color-mix(in srgb, red 30%, blue 30%)is a purple at 60% opacity. - Mixing with
transparentfades a color:color-mix(in srgb, red, transparent)is red at 50% opacity, not a darker red, because colors are mixed with their alpha taken into account.
Choosing the space
The same two colors give different results in different spaces:
body { font: 600 0.8rem system-ui, sans-serif; }
.row { display: grid; grid-template-columns: 7rem repeat(5, 1fr); gap: 6px; align-items: center; margin-bottom: 6px; }
.row span { height: 2.5rem; border-radius: 6px; }
.srgb span:nth-of-type(2) { background: color-mix(in srgb, #d62828 75%, #1d4ed8); }
.srgb span:nth-of-type(3) { background: color-mix(in srgb, #d62828, #1d4ed8); }
.srgb span:nth-of-type(4) { background: color-mix(in srgb, #d62828 25%, #1d4ed8); }
.oklab span:nth-of-type(2) { background: color-mix(in oklab, #d62828 75%, #1d4ed8); }
.oklab span:nth-of-type(3) { background: color-mix(in oklab, #d62828, #1d4ed8); }
.oklab span:nth-of-type(4) { background: color-mix(in oklab, #d62828 25%, #1d4ed8); }
.oklch span:nth-of-type(2) { background: color-mix(in oklch, #d62828 75%, #1d4ed8); }
.oklch span:nth-of-type(3) { background: color-mix(in oklch, #d62828, #1d4ed8); }
.oklch span:nth-of-type(4) { background: color-mix(in oklch, #d62828 25%, #1d4ed8); }
.row span:nth-of-type(1) { background: #d62828; }
.row span:nth-of-type(5) { background: #1d4ed8; }
oklabgives even, natural blends, and is the best default, especially for tints and shades.srgboften makes the middle of a mix darker and duller.- Polar spaces (
oklch,hsl) travel around the hue wheel, keeping colors vivid: red to blue passes through magenta. Add a hue interpolation method to choose the direction:shorter hue(the default),longer hue,increasing hueordecreasing hue, as incolor-mix(in oklch longer hue, red, blue), which goes the long way, through yellow and green.

The blue to yellow rows show a limit of every rectangular space: for colors on opposite sides of the hue wheel, the straight path runs through gray. Polar spaces avoid the gray by traveling around the wheel, at the price of hues that aren't in either starting color.
Mixing with currentColor
color-mix() accepts any color, including currentColor and custom properties, so derived colors follow their source:
.tag {
color: var(--tag-color, #2f7d4f);
background: color-mix(in oklab, currentColor 12%, transparent); /* a faint tint of the text color */
border: 1px solid color-mix(in oklab, currentColor 40%, transparent);
}
Change the tag's color, and its background and border follow.
Relative color syntax
Relative color syntax starts from an origin color, written after from, splits it into channels, and lets you keep or change each one:
--brand: #8a3b12;
--brand-faded: oklch(from var(--brand) l c h / 40%); /* same color, 40% opacity */
--brand-lighter: oklch(from var(--brand) calc(l + 0.2) c h); /* lighter */
--brand-muted: oklch(from var(--brand) l calc(c * 0.4) h); /* less colorful */
--brand-complement: oklch(from var(--brand) l c calc(h + 180)); /* opposite hue */
--brand-gray: oklch(from var(--brand) l 0 h); /* same lightness, no color */
- The function you use, here
oklch(), decides which channel keywords are available:l,candhinoklch();r,gandbinrgb();h,sandlinhsl(); andalphain all of them. - The origin can be any color in any notation. It's converted into the function's color space first, so you can write a palette in hex and derive variants in
oklch(). - Channel keywords are plain numbers, in the function's numeric range. In
oklch(),lgoes from 0 to 1, so writecalc(l + 0.2), notcalc(l + 20%). Inhsl(),sandlgo from 0 to 100:hsl(from red h s calc(l + 20)). Inrgb(), channels go from 0 to 255. - Each channel can be a keyword, a new value, or a
calc()using any of the keywords. You can even swap channels:rgb(from x b g r). color(from x display-p3 r g b)converts an origin into another RGB space.currentColorworks as an origin in current browsers.alpha(from x / 50%)changes only the alpha, without picking a color space. It's Baseline since September 2026.
Relative colors are Baseline since September 2024.
color-mix() or relative colors?
| Need | Easier with |
|---|---|
| tint or shade toward white or black | color-mix(in oklab, x, white 30%) |
| blend two brand colors | color-mix() |
| transparent version | alpha(from x / 50%), oklch(from x l c h / 50%) or color-mix(in srgb, x 50%, transparent) |
| set an exact lightness | relative: oklch(from x 0.95 c h) |
| rotate the hue, change chroma | relative |
| make a gray matching a color's lightness | relative: oklch(from x l 0 h) |
Deriving a full set of states
A component can derive all its states from one property:
body { font-family: system-ui, sans-serif; display: flex; gap: 0.75rem; padding: 1rem; flex-wrap: wrap; }
.btn {
--base: #8a3b12;
font: inherit; font-weight: 600; padding: 0.6em 1.2em; border-radius: 8px; cursor: pointer;
color: white; background: var(--base); border: 2px solid oklch(from var(--base) calc(l - 0.1) c h);
}
.btn:hover { background: oklch(from var(--base) calc(l + 0.08) c h); }
.btn:active { background: oklch(from var(--base) calc(l - 0.08) c h); }
.btn.soft { color: var(--base); background: color-mix(in oklab, var(--base) 12%, white); border-color: transparent; }
.btn.green { --base: #2f7d4f; }
.btn.blue { --base: oklch(from #8a3b12 l c 255); }
Changing --base gives every state a matching color, and the last button shows a hue rotation of the brand color.

Each row comes from one custom property. The columns stay consistent across hues because every state moves lightness by the same amount.
Palettes from one token
:root {
--brand: oklch(55% 0.14 45);
--brand-50: color-mix(in oklab, var(--brand) 8%, white);
--brand-100: color-mix(in oklab, var(--brand) 18%, white);
--brand-300: color-mix(in oklab, var(--brand) 55%, white);
--brand-700: color-mix(in oklab, var(--brand), black 30%);
--brand-900: color-mix(in oklab, var(--brand), black 60%);
}
Mixing toward white or black lowers chroma as well as changing lightness, which usually looks natural for tints. For more control, set exact steps with relative colors: oklch(from var(--brand) 0.95 calc(c * 0.3) h).
Remember where custom properties resolve (article 27): tokens derived on :root are computed there. If a theme redefines --brand on a section, redefine the derived tokens there too, or compute them where they're used.
What's current
color-mix()is Baseline widely available since November 2025. Mixing more than two colors is in Firefox 150 and Safari 27, not yet in Chrome.- Leaving out the
in <space>part, which then defaults tooklab, is a recent change: write the space for now. alpha(), for changing only a color's opacity, is Baseline since September 2026.- Relative color syntax is Baseline since September 2024.
Common questions
Why does oklch(from red calc(l + 10%) c h) not work?
Channel keywords are numbers, so l is between 0 and 1 in oklch(). Adding a percentage to a number is invalid. Write calc(l + 0.1).
Why does mixing a color with transparent not make it darker?
Mixing takes alpha into account (premultiplied), so the transparent color's black channels don't count. The result is the same color at lower opacity.
Which color space should I mix in?
oklab for tints, shades and most blends. oklch when you want to keep colors vivid between two different hues. srgb mainly for matching older tools.
Can I use color-mix() with custom properties?
Yes, and it's the most common use. Just remember that a custom property holding an invalid color makes the declaration invalid at computed-value time.
Is relative color syntax the same as Sass's lighten()?
Similar in purpose, but it runs in the browser, so it works with values that change at runtime, such as themes, currentColor and custom properties set by JavaScript.
Summary
color-mix(in space, a p%, b q%)blends two colors. Percentages set the proportions, and totals under 100% add transparency.- Mix in
oklabfor even results. Polar spaces keep hues vivid and acceptshorter,longer,increasingordecreasing hue. - Relative color syntax,
oklch(from x l c h), converts an origin color and exposes its channels as numbers forcalc(). - Use relative colors for exact lightness, chroma, hue and alpha changes, and
color-mix()for blending. - Derive states, tints and transparent versions from one token, but redefine derived tokens where themes change the base.
Practice questions
Write a border that's the element's text color at 30% opacity, in two different ways.
Answer
border-color: color-mix(in srgb, currentColor 30%, transparent);
border-color: rgb(from currentColor r g b / 30%);
What does color-mix(in srgb, red 40%, blue 40%) produce?
Answer
A purple (an equal mix of red and blue) at 80% opacity. The percentages add up to less than 100%, so the remainder becomes transparency.
From --accent: #2f7d4f, derive a color with the same lightness and chroma but a blue hue, and a version 15% darker.
Answer
--accent-blue: oklch(from var(--accent) l c 255);
--accent-dark: oklch(from var(--accent) calc(l - 0.15) c h);
A theme redefines --brand inside .holiday, but --brand-100, defined on :root with color-mix(), still uses the old color. Why?
Answer
--brand-100 is computed on the root, with the root's --brand, and inherits as that finished color. Redefine --brand-100 inside .holiday too, or compute the mix in the rules that use it.
Previous: Color Spaces and Gamuts: lab(), lch(), oklab(), oklch() and color()
Next: Light and Dark Themes: color-scheme, light-dark(), System Colors and accent-color

More in CSS Course
Quiz: CSS Delicate Details
Twenty-five questions on the edge cases that surprise experienced developers: invalid custom properties, shorthands that reset values, layer order with !important, containing blocks, margin collapsing, specificity of :is() and :where(), intrinsic minimum sizes, and more, each checked in Chrome.
Quiz: CSS Interview Questions
Thirty front-end interview questions: cascade, specificity and layers, box model and margin collapsing, stacking contexts, positioning, flexbox and grid, responsive design, custom properties, performance, accessibility, modern selectors and architecture.
Quiz: CSS Course Final Exam
Thirty questions across the whole CSS course: syntax and error handling, selectors, the cascade and layers, values and units, color, the box model, backgrounds, positioning, flexbox, grid, responsive design, typography, generated content, effects, transforms, motion and architecture.
Quiz: CSS Architecture, Tooling and Debugging (CSS Part 17)
Twenty questions on modular CSS and BEM, layering a stylesheet, design tokens and theming, pattern libraries and safe refactoring, preprocessors and build tools, the at-rules reference, and debugging common CSS problems.
Discussion
Sign in to ask a question or share what you learned.