What color-mix() does
color-mix() blends two colors in a chosen color space. In a component system, the useful part is not making gradients: it is deriving a whole set of UI colors from one token.

For example, if --brand is the only theme variable, a button can derive its hover background, border, focus ring, and pressed shade:
color-mix(in srgb, var(--brand), black 12%)darkens the brand color.color-mix(in srgb, var(--brand), white 70%)creates a light tint.color-mix(in srgb, var(--brand) 10%, transparent)creates a translucent brand wash.
The percentages describe how much of each color enters the mix. When only one percentage is supplied, the other color gets the remainder.

One-token component theming
Save this as an HTML file and open it in a modern browser. It includes a default button, a locally themed button, a callout, and a modal scrim.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>color-mix component demo</title>
<style>
:root {
--brand: #2563eb;
--page: #f8fafc;
--text: #0f172a;
--muted: #475569;
--surface: #ffffff;
--brand-strong: color-mix(in srgb, var(--brand), black 10%);
--brand-hover: color-mix(in srgb, var(--brand), black 8%);
--brand-press: color-mix(in srgb, var(--brand), black 18%);
--brand-border: color-mix(in srgb, var(--brand), black 22%);
--brand-ring: color-mix(in srgb, var(--brand) 35%, transparent);
--brand-tint: color-mix(in srgb, var(--brand) 10%, white);
--on-brand: #ffffff;
}
* { box-sizing: border-box; }
body {
margin: 0;
min-height: 100vh;
padding: 32px;
font: 16px/1.5 system-ui, -apple-system, Segoe UI, sans-serif;
background: var(--page);
color: var(--text);
}
.demo {
display: grid;
gap: 20px;
max-width: 760px;
margin: auto;
}
.row {
display: flex;
flex-wrap: wrap;
gap: 12px;
align-items: center;
}
.btn {
appearance: none;
border: 1px solid var(--brand-border);
border-radius: 10px;\n padding: 10px 16px;
font: inherit;
font-weight: 650;
color: var(--on-brand);
background: var(--brand);
cursor: pointer;
transition: background 160ms ease, border-color 160ms ease, transform 80ms ease;
}
.btn:hover { background: var(--brand-hover); }
.btn:active {
background: var(--brand-press);
transform: translateY(1px);
}
.btn:focus-visible {
outline: 3px solid var(--brand-ring);
outline-offset: 2px;
}
.btn.theme-sale {
--brand: #c2410c;
--on-brand: #fff7ed;
}
.callout {
border: 1px solid color-mix(in srgb, var(--brand) 35%, white);
border-left-width: 4px;
border-radius: 12px;
padding: 16px;
background: var(--brand-tint);
}
.callout strong {
display: block;
margin-bottom: 4px;
color: color-mix(in srgb, var(--brand), black 28%);
}
.callout p {
margin: 0;
color: var(--text);
}
.scrim {
position: fixed;
inset: 0;
display: grid;
place-items: center;
padding: 20px;
background: color-mix(in srgb, var(--brand) 18%, #0f172a);
backdrop-filter: blur(6px);
}
.dialog {
width: min(420px, 100%);
border-radius: 16px;
padding: 22px;
background: var(--surface);
box-shadow: 0 24px 70px rgb(15 23 42 / 30%);
}
.dialog h2 { margin: 0 0 8px; font-size: 20px; }
.dialog p { margin: 0 0 18px; color: var(--muted); }
</style>
</head>
<body>
<main class="demo">
<div class="row">
<button class="btn" type="button">Default action</button>
<button class="btn theme-sale" type="button">Local campaign action</button>
</div>
<section class="callout" aria-label="Storage notice">
<strong>Storage almost full</strong>
<p>Export older projects to keep automatic backups running smoothly.</p>
</section>
<div class="scrim">
<section class="dialog" role="dialog" aria-modal="true" aria-labelledby="dialog-title">
<h2 id="dialog-title">Publish changes?</h2>
<p>The new color tokens will be applied to every button using the default theme.</p>
<button class="btn" type="button">Publish</button>
</section>
</div>
</main>
</body>
</html>
The local campaign button works because custom properties inherit and participate in the cascade. Set --brand on a card, sidebar, or product wrapper, and every derived state follows it.
Translucent surfaces
Mixing with transparent is convenient, but understand the alpha result.
This declaration:
color-mix(in srgb, var(--brand) 10%, transparent)
produces a color with roughly 10% alpha. If --brand is opaque, the result is conceptually close to taking the brand RGB channels and setting alpha to 0.1. It is not a 10% opaque white layer, and it is not the same as placing a fully opaque tint over every possible background.
For a blue brand like #2563eb, the result is approximately rgb(37 99 235 / 0.1). The exact equivalent can differ when the input already has alpha or when interpolation uses premultiplied colors, so treat that as a mental model, not a universal conversion rule.
Use translucent mixes for scrims, selected rows, focus rings, and glassy cards. Do not use them as a substitute for testing text contrast over photos.
OKLCH vs sRGB
srgb is predictable for typical design-system adjustments: mixing with black, white, or transparent behaves close to familiar RGBA workflows.
oklch and oklab often create smoother perceptual transitions, especially when interpolating between different hues. The tradeoff is that generated midpoint colors can look less obvious to predict and may cross into colors outside the normal sRGB gamut. For simple derived states, I usually start with in srgb, then compare in oklch for gradients or large tint scales.
--hover-srgb: color-mix(in srgb, var(--brand), black 10%);
--hover-oklch: color-mix(in oklch, var(--brand), black 10%);
Put both side by side on your actual components. The best-looking interpolation method depends on the source hue and the UI surface, not the syntax alone.
Relative color syntax
Relative color syntax is a separate feature. It lets you start from an existing color and adjust channels in a color function. It is useful when you want channel-level control rather than a blend.
@supports (background: rgb(from red r g b / 90%)) {
:root {
--brand-90: rgb(from var(--brand) r g b / 90%);
}
}
@supports not (background: rgb(from red r g b / 90%)) {
:root {
--brand-90: rgb(37 99 235 / 0.9);
}
}
Keep this support test separate from color-mix(). A browser can support one feature without supporting the syntax you need for the other.
Fallbacks and browser support
Support for color-mix() is good in current evergreen browsers, but your audience may include older managed devices or embedded web views. Rather than quoting release numbers in a tutorial that can age quickly, check current support tables before release and decide against your own analytics.
The safest pattern is static values first, enhancement second:
:root {
--brand: #2563eb;
--brand-hover: #1d4ed8;
--brand-press: #1e40af;
--brand-border: #1e3a8a;
--brand-ring: rgb(37 99 235 / 0.35);
--brand-tint: #dbeafe;
--on-brand: #ffffff;
}
@supports (background: color-mix(in srgb, red, blue)) {
:root {
--brand-hover: color-mix(in srgb, var(--brand), black 8%);
--brand-press: color-mix(in srgb, var(--brand), black 18%);
--brand-border: color-mix(in srgb, var(--brand), black 22%);
--brand-ring: color-mix(in srgb, var(--brand) 35%, transparent);
--brand-tint: color-mix(in srgb, var(--brand) 10%, white);
}
}
@supports not (background: color-mix(in srgb, red, blue)) {
.btn.theme-sale {
--brand-hover: #9a3412;
--brand-press: #7c2d12;
--brand-border: #431407;
--brand-ring: rgb(194 65 12 / 0.35);
--brand-tint: #ffedd5;
}
}
This cascade is easy to audit: the component always consumes variables, and only the token-generation layer changes.
For a production theme switcher, keep the raw color and derived tokens together. The percentages below are useful rules of thumb, not universal contrast guarantees.
const themes = {
blue: {
brand: "#2563eb",
hover: "#1d4ed8",
press: "#1e40af",
tint: "#dbeafe",
on: "#ffffff"
},
plum: {
brand: "#7c3aed",
hover: "#6d28d9",
press: "#5b21b6",
tint: "#ede9fe",
on: "#ffffff"
}
};
function applyTheme(name) {
const t = themes[name];
const root = document.documentElement;
root.style.setProperty("--brand", t.brand);
root.style.setProperty("--brand-hover", t.hover);
root.style.setProperty("--brand-press", t.press);
root.style.setProperty("--brand-tint", t.tint);
root.style.setProperty("--on-brand", t.on);
}
applyTheme("blue");
If you rely heavily on generated colors, consider building static derivatives during your design-token build step. Modern CSS can generate them in the browser, but generated token JSON is still the most conservative shipping option for large products.
Accessibility checks
Aim for at least 4.5:1 contrast for normal button text and 3:1 for large text or meaningful UI boundaries. Disabled styles can be lower, but they should not be the only way a disabled state is communicated.
Check these combinations directly:
- Default label over the button fill.
- Hover and pressed labels over their derived fills.
- Callout body text over the tinted surface.
- Focus ring against the page and nearby components.
- Dialog text over a scrim placed above representative imagery.
Translucent surfaces need composite testing. A scrim over a light photo behaves differently from the same scrim over a dark video. Add a stronger overlay, a solid text container, or a text shadow only when needed. A shadow can improve legibility but should not replace a measured contrast pass.
Do not assume white text works for every brand. For very light brand colors, switch to dark text manually:
.btn.theme-warning {
--brand: #f59e0b;
--brand-hover: #d97706;
--brand-press: #b45309;
--brand-border: #92400e;
--brand-tint: #fef3c7;
--on-brand: #1f2937;
}
Future color-contrast functions may automate text selection, but support and syntax details should be checked before use. Today, the robust approach is explicit --on-brand tokens, paired with contrast testing in the browser and against real content.