CSS color recipe

Gradients in OKLCH Vivid all the way across, without the grey middle

A gradient blends its stops in sRGB unless you say otherwise, and opposite hues meet in a dull grey. linear-gradient(to right in oklch, …) walks around the hue wheel instead, so the middle keeps its color.

See it run
Baseline
Newly available
First versions
Chrome 111 · Firefox 127 · Safari 16.2
Tested
3 of 3 engines

Live example

The recipe, running

Left: the CSS below, as your browser runs it. Right: the same CSS as a browser without the feature reads it, so you see exactly what the fallback gives.

Turn on JavaScript to see whether your browser supports it; the examples work either way.

As written, in your browser
In a browser without it

In each example the top bar is the default, blended in sRGB, and the bottom bar is the same two colors in OKLCH. Without the feature, the bottom bar is the sampled fallback.

The CSS

Copy it as it is

This is the exact CSS the example runs. Fallbacks come first; the modern values follow, so each browser keeps the last line it understands.

gradient-interpolation.css

/* Default: interpolated in sRGB, which greys out in the middle. */
.ramp--srgb { background: linear-gradient(to right, #0058FF, #FFD400); }

/* Stops sampled along the OKLCH path keep older browsers close. */
.ramp--oklch {
  background: linear-gradient(to right, #0058FF, #0096B7 25%, #00BBA2 50%, #7CD846 75%, #FFD400);
  background: linear-gradient(to right in oklch, #0058FF, #FFD400);
}

.ramp { height: 44px; border-radius: 8px; }
.ramp + .ramp { margin-top: 10px; }

How it works

What each part does

  1. The fallback samples the OKLCH path. Three extra stops at 25%, 50% and 75%, worked out along the same OKLCH route, give older browsers a ramp close to the real one.

  2. Shorter hue by default. OKLCH takes the shorter way around the wheel; add longer hue to go the long way.

  3. Two declarations are enough. The value has no var(), so a browser that cannot read in oklch keeps the sampled version.

Browser support

Where it runs

First version of each browser with the feature, from the web-features project and MDN’s browser-compat-data. “No” means not supported yet.

  • Gradient interpolationNewly availableBaseline newly available since 11 June 2024: every core browser has it, but older versions in use may not.
First supporting version by browser
BrowserGradient interpolation
Chrome111
Chrome for Android111
Edge111
Firefox127
Firefox for Android127
Safari16.2
Safari on iOS16.2

Support reviewed on against web-features 98723fd and browser-compat-data 3b28abe.

Tested

Tested in three engines

Engines this recipe was run in
EngineVersionSupportedAs writtenFallback
Chromium147.0.7727.15YesPassPass
Firefox148.0.2YesPassPass
WebKit26.4YesPassPass

Run on in Chromium 147.0.7727.15, Firefox 148.0.2 and WebKit 26.4, with Playwright.

Accessibility

Measured, not assumed

The midpoint of the sRGB ramp has an OKLCH chroma of 0.041; the OKLCH ramp’s midpoint keeps 0.130.

  • Midpoint in sRGB0.041
  • Midpoint in OKLCH0.130

References

Go to the source