Search tools

Color guides

CSS color-mix() in OKLCH vs sRGB: Hover States & Tints

Generate hover states, soft surface tints, and theme accents from one CSS variable with color-mix(). See why in oklch avoids sRGB hue shifts and contrast drops.

3D studio render of two beveled circular optical glass lenses in cobalt blue and warm amber overlapping to form a glowing rose-magenta center on a dark slate floor

Use CSS color-mix(in oklch, var(--brand) 82%, black) to build button hover states, soft badge tints, and themeable borders straight from a single CSS custom property. No Sass functions, no extra color tokens, and no translucent opacity hacks that bleed page backgrounds through your buttons.

You only need two rules to get clean results: use in oklch (or in oklab) when mixing a brand color with white or black so hues never drift, and always test the resulting hover shade in a WCAG contrast checker.

:root {
  --brand: #2f6f68;
  --brand-hover: color-mix(in oklch, var(--brand) 82%, black);
  --brand-soft: color-mix(in oklch, var(--brand) 14%, white);
  --brand-border: color-mix(in oklch, var(--brand) 35%, white);
}

Why opacity: 0.8 breaks button contrast on hover

Many stylesheets fake a hover state with .btn:hover { opacity: 0.82; }. That fades the button toward whatever sits behind it, which lowers contrast instead of strengthening it.

Take a solid #2F6F68 button carrying crisp #FFFFFF text on a white #FFFFFF page:

  • Default button (#2F6F68): 5.84:1 contrast (passes WCAG AA).
  • Hover with opacity: 0.82: composites to #548983, dropping contrast to 3.97:1 (fails WCAG AA 4.5:1).
  • Hover with color-mix(in srgb, #2F6F68 82%, black): solid #275B55 at 7.74:1 (AAA).
  • Hover with color-mix(in oklch, #2F6F68 82%, black): solid #22544E at 8.64:1 (AAA), with a clean perceptual darkening step and zero background bleed.

css-color-mix-oklch-vs-srgb-hover-tints-diagram

Why in oklch beats in srgb for tints and two-hue blends

Mixing in sRGB averages red, green, and blue channels linearly. That causes two visual bugs that designers constantly fight:

1. Blue and indigo tints turn purple in sRGB

Mix Tailwind Indigo (#4F46E5, OKLCH hue 277.0°) with white to create soft banner backgrounds or secondary button fills:

Tint Strength color-mix(in srgb, ...) color-mix(in oklch, ...)
50% #4F46E5 + white #A7A2F2 (hue drifts +8.9° to 285.9°) #9DA9F8 (hue locked at 277.0°)
30% #4F46E5 + white #CAC8F7 (hue drifts +10.5° to 287.5°) #C3CBFC (hue locked at 277.0°)
15% #4F46E5 + white #E5E3FB (noticeably lavender, 288.4°) #E0E5FE (crisp true indigo, 277.0°)

If you want to understand why perceptual lightness and constant hue work so well here, read our breakdown of OKLCH vs HSL for UI palettes.

2. Mixing two bright hues turns muddy gray in sRGB

Try blending bright blue (#2563EB) and warm amber (#F59E0B) at 50/50 across four CSS interpolation spaces:

  • in srgb: #8D807B (flat, muddy gray-brown; chroma drops to 0.017).
  • in oklab: #938EA4 (clean muted slate along a straight line through OKLab).
  • in oklch (shorter hue arc): #DF57A9 (vivid rose-magenta at 346.5°).
  • in oklch longer hue: #00B477 (vivid emerald green traveling the opposite arc around the wheel).

That is the exact same math that fixes dead midpoints in CSS gradients, covered in our guide on why CSS gradients have a gray band.

Practical CSS patterns you can ship today

Adaptive light and dark theme tokens

Because color-mix() runs live in the browser, you can flip a single --mix-target variable in dark mode and every hover and active state adapts automatically:

:root {
  --brand: #2f6f68;
  --surface: #ffffff;
  --mix-hover: black;
}

[data-theme="dark"] {
  --surface: #14171b;
  --mix-hover: white;
}

.button {
  background: var(--brand);
  color: #ffffff;
}

.button:hover {
  background: color-mix(in oklch, var(--brand) 84%, var(--mix-hover));
}

.badge {
  background: color-mix(in oklch, var(--brand) 16%, var(--surface));
  border: 1px solid color-mix(in oklch, var(--brand) 40%, var(--surface));
}

Soft alpha washes from any CSS variable

Need a semi-transparent focus glow or card wash from a hex variable? Mix your token with transparent:

.input:focus-visible {
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 22%, transparent);
}

When mixing with transparent, in srgb is ideal because you only want to scale the alpha channel without shifting the underlying RGB channels.

CSS color-mix() FAQ

Do all major browsers support color-mix()?

Yes. Chrome 111+, Edge 111+, Firefox 113+, and Safari 16.2+ all support color-mix() natively, making it part of Baseline across modern browsers.

Should I use in oklab or in oklch with white and black?

For mixing a single color with pure white or black, in oklab and in oklch produce identical hex values because black and white have zero chroma. Use in oklab when you want neutral, calm blends between two different hues, and in oklch when you want vibrant, saturated midpoints.

Can color-mix() replace a full 50-to-950 design system scale?

It covers hover states, active presses, and subtle surface washes cleanly. For full 50-to-950 UI ramps where chroma needs bell-curve shaping at very light and dark stops, generate calibrated steps in our color converter and tonal scale tool.

Read next