Backgrounds✨ Premium

Color Mix Crossfade

Three CSS blocks compare color-mix() blending paths live — oklch vs sRGB, zero JavaScript.

CSScolor-mix()OKLCH

You'll get access to the interactive demo with a free account.

This effect is part of Effect.Labs — 811 vanilla effects, some free, some premium. Backgrounds has 50 effects, including 6 free. Explore the category →

3 usage examples

Design tool — Blend comparator inside a palette selector — Color Mix Crossfade example 1

① Design tool — Blend comparator inside a palette selector

WhenA design tool or design-system UI shows the resulting color between two user-selected hues in real time.
WhyThe built-in oklch / sRGB comparison visually explains why oklch blending produces a more saturated result — a teaching moment without extra text.
SettingsBlock A: brand primary in oklch; block B: secondary color; mix block widened to 100 px at rest to emphasize the visible result.
Documentation article — Live color-mix() demo — Color Mix Crossfade example 2

② Documentation article — Live color-mix() demo

WhenA CSS reference page or technical blog post explains <code>color-mix()</code> and wants an interactive inline demo without a framework.
WhyThe effect is self-explanatory: hovering changes the blend space and the difference is immediately visible — more effective than any static example.
SettingsAdapt the .crossfade-info text to the context (e.g. hover: oklch → lab); adjust colors to match the article's examples.
CSS e-learning module — Interactive blend-space exercise — Color Mix Crossfade example 3

③ CSS e-learning module — Interactive blend-space exercise

WhenAn advanced CSS course or workshop presents an exercise where learners hover the blocks and observe how the midpoint color shifts when the blend space changes.
WhyThe three-column layout is the exercise itself: comparing oklch and sRGB live is the learning objective — the one context where showing all three blocks side by side serves a genuine purpose.
SettingsDefault oklch(.65 .28 30) / oklch(.6 .25 260) values come straight from the effect code; transitions at 1 s (`.block-mix`) and 1.2 s (`.block-a`, `.block-b`) let learners follow the change step by step; adapt `.crossfade-info` to the course instruction text.

How it works

The CSS color-mix() function takes two colors and a color space, then returns the color at the midpoint of the path between them in that space. The effect places two instances side by side: the center block shows color-mix(in oklch, …) at rest, and switches to color-mix(in srgb, …) on hover — via a :hover selector alone, no JavaScript.

The visual difference comes from the geometry of each space: oklch is perceptually uniform (L = constant lightness, C = chroma, H = hue), so the midpoint between an orange-red oklch(.65 .28 30) and a blue-violet oklch(.6 .25 260) produces a saturated purple. sRGB linearly interpolates its raw R, G, B channels — the path crosses the center of the RGB cube, which desaturates the result toward a muddy gray.

On hover of the .crossfade-container, three changes trigger at once: blocks A and B shift apart by 20 px via transform: translateX(±20px), the mix block widens from 60 px to 120 px, and its background switches from the oklch version to the sRGB version. Every animation is driven by the transition properties declared on each block (1.2 s for A and B, 1 s for the mix). The active blend space is indicated by the .crossfade-info label that gains opacity on hover.

Accessibility

  • ⚠️ prefers-reduced-motion is absent: transitions (1.2 s and 1 s) run regardless of system preference. Add @media (prefers-reduced-motion: reduce) { .crossfade-block { transition: none } } before deploying to production.
  • The interaction is triggered by :hover only — keyboard users cannot trigger the comparison without an additional script.
  • .crossfade-info is a <span> in the DOM flow — its text is read by screen readers.
  • No role or aria-label on the colored blocks — they are purely decorative in the original demo.
  • .crossfade-info contrast: white at 60% opacity on #0f0f1a — ratio below the WCAG AA threshold for small text (target 4.5:1 not met).

Browser compatibility

Requires color-mix() and oklch() — available in all modern browsers since early 2023.

Chrome 111+✓ Full
Firefox 113+✓ Full
Safari 16.2+✓ Full
Edge 111+✓ Full
Mobile iOS 16.2+✓ Full
Android Chrome 111+✓ Full

Without <code>color-mix()</code> or <code>oklch()</code> support, the mix block renders without a background (transparent); blocks A and B may also lose their color. No JS error — degradation is silent.

The code

HTML structure to paste into your page (CSS + JS available with a premium account):

index.html — structure
<div class="demo-preview">
  <div class="chroma-demo crossfade-container">
    <div class="crossfade-blocks">
      <div class="crossfade-block block-a"></div>
      <div class="crossfade-block block-mix"></div>
      <div class="crossfade-block block-b"></div>
    </div>
    <span class="crossfade-info">hover: oklch → srgb blend path</span>
  </div>
</div>
🔒 Unlock the full code — from €2.99 the first month

Full HTML + CSS + JS, copy-paste ready — with hundreds of premium effects.

Customize

Options passed to the API or data-* attributes:

Option / propertyDefaultEffect
.block-a { background } oklch(.65 .28 30) First source color. Accepts any valid CSS format: hex, rgb, hsl, oklch.
.block-b { background } oklch(.6 .25 260) Second source color. Keeping both in the same space (oklch + oklch) gives the most predictable results.
color-mix(in oklch, …) — rest oklch Blend space shown at rest. Replace with lch, lab, or hsl for a different starting comparison.
color-mix(in srgb, …) — hover srgb Blend space revealed on hover. The oklch / sRGB pair shows the most striking contrast; try oklch / hsl for another perspective.
.crossfade-block { transition } 1.2s Duration of the A and B block translation. Reduce to 0.4 s for a snappy response, increase to 2 s for a slow crossfade.
.block-mix { width } / hover 120px 60px / 120px Mix block width at rest and on hover. Increase the hover value to emphasize the result; reduce both for more compact blocks.
.crossfade-info (text) "hover: oklch → srgb blend path" Descriptive label below the blocks. Update it to reflect the color spaces you are comparing.

FAQ

Chrome 111+ and Edge 111+ (March 2023), Firefox 113+ (May 2023), Safari 16.2+ (March 2023). Global coverage exceeds 90% by end of 2024. For older browsers, add a background: #hex fallback just before the color-mix() rule — browsers that don't recognize the value apply the previous one.
Replace hard-coded values with CSS custom properties: background: var(--color-a) and color-mix(in oklch, var(--color-a), var(--color-b)). Update them from JavaScript: el.style.setProperty('--color-a', newColor). color-mix() recomputes the result immediately.
Yes — add extra blocks with different spaces (color-mix(in lab, …), color-mix(in hsl, …)) and reveal them on other states: :focus-within, a JS-toggled class on click, or cascading :hover selectors. The CSS structure is identical for each additional block.