Gradient Interpolation Spaces
The same two colours blended in sRGB, HSL and OKLCH, showing why some gradients go grey and muddy in the middle.
AI prompt
Colour theory sheet showing the same two-colour gradient from saturated blue to bright yellow in three horizontal bars: top bar blended in sRGB passing through a dull grey middle, middle bar blended in HSL passing through a vivid green and cyan, bottom bar blended in OKLCH passing through a clean even green, labelled sRGB, HSL and OKLCH beneath each, flat layout on a white background, generous spacing. Negative: banding, noise, text errors, decorative frames. Reduced motion: static sheet.About this pattern
Definition
A gradient is a path between two colours, and the path depends on the colour space it is blended in. Plain sRGB blending runs straight through the middle and can turn grey; HSL swings around the hue wheel and can look garish; OKLCH keeps lightness and chroma steady and gives smooth, vivid blends.
When to use it
- Blue to yellow in sRGB passes through dull grey; in OKLCH it passes through a clean green.
- CSS can choose the space: linear-gradient(in oklch, blue, yellow).
- Check the hue path too: oklch has shorter and longer hue arcs for control.
What the controls do
- Two colour pickers and quick pairs; three bars show each interpolation space.
Motion & timing
- Bars update on input; no animation.
- Reduced motion: nothing to change.
Tips & variations
- Provide a fallback for browsers without support: a plain gradient still works.
- Test text over the gradient at several points, not just the ends.
Code of this live preview
<div class="bx"><div class="two"><label class="rw">From<input id="c1" type="color" value="#1f4fd8"></label><label class="rw">To<input id="c2" type="color" value="#ffd23f"></label></div><div class="pre" id="pre" role="group" aria-label="Pairs"><button data-p="0" aria-pressed="true">Blue to yellow</button><button data-p="1" aria-pressed="false">Red to green</button><button data-p="2" aria-pressed="false">Purple to orange</button></div><div class="gs" id="gs"></div></div>:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}a{color:inherit;text-decoration:none}ul,ol,p,h4{margin:0;padding:0}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
input[type=color]{width:60px;height:30px;border:1px solid var(--line);border-radius:8px;padding:2px;background:var(--surface);cursor:pointer}.gs{display:grid;gap:8px}.gs div{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.gs i{height:34px;border-radius:8px;display:block;border:1px solid rgba(0,0,0,.06)}.gs b{color:var(--text)}.gs small{font-size:10.5px}.two{display:grid;grid-template-columns:1fr 1fr;gap:12px}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}const Pr=[['#1f4fd8','#ffd23f'],['#e5252a','#1f9d55'],['#7b2cbf','#ff8c1a']],c1=document.getElementById('c1'),c2=document.getElementById('c2'),gs=document.getElementById('gs'),bs=[...document.querySelectorAll('#pre button')];let p=0;
const sp=[['sRGB','in srgb','Straight line between the colours; the middle can go grey.'],['HSL','in hsl','Swings around the hue wheel; vivid but sometimes garish.'],['OKLCH','in oklch','Even lightness and chroma; smooth, clean blends.']];
function up(){const ok=CSS.supports('background','linear-gradient(in oklch, red, blue)');gs.innerHTML=sp.map(s=>'<div><b>'+s[0]+'</b><i style="background:'+(ok?'linear-gradient(to right '+s[1]+','+c1.value+','+c2.value+')':'linear-gradient(to right,'+c1.value+','+c2.value+')')+'"></i><small>'+(ok?s[2]:'This browser does not support gradient colour spaces; showing plain sRGB.')+'</small></div>').join('');}
bs.forEach(b=>b.addEventListener('click',()=>{p=+b.dataset.p;c1.value=Pr[p][0];c2.value=Pr[p][1];bs.forEach(k=>k.setAttribute('aria-pressed',String(k===b)));up();}));[c1,c2].forEach(i=>i.addEventListener('input',()=>{bs.forEach(k=>k.setAttribute('aria-pressed','false'));up();}));up();One complete HTML file. Save it and open it in a browser.
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Gradient Interpolation Spaces — demo</title>
<style>
:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
html,body{height:100%}body{background:var(--bg);color:var(--text);font:15px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Inter,Roboto,sans-serif;-webkit-font-smoothing:antialiased}.stage{min-height:100%;display:grid;place-items:center;padding:24px}button,input,select,textarea{font-family:inherit}@media (prefers-reduced-motion:reduce){html{scroll-behavior:auto}}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}a{color:inherit;text-decoration:none}ul,ol,p,h4{margin:0;padding:0}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
input[type=color]{width:60px;height:30px;border:1px solid var(--line);border-radius:8px;padding:2px;background:var(--surface);cursor:pointer}.gs{display:grid;gap:8px}.gs div{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.gs i{height:34px;border-radius:8px;display:block;border:1px solid rgba(0,0,0,.06)}.gs b{color:var(--text)}.gs small{font-size:10.5px}.two{display:grid;grid-template-columns:1fr 1fr;gap:12px}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
</style></head>
<body><div class="stage">
<div class="bx"><div class="two"><label class="rw">From<input id="c1" type="color" value="#1f4fd8"></label><label class="rw">To<input id="c2" type="color" value="#ffd23f"></label></div><div class="pre" id="pre" role="group" aria-label="Pairs"><button data-p="0" aria-pressed="true">Blue to yellow</button><button data-p="1" aria-pressed="false">Red to green</button><button data-p="2" aria-pressed="false">Purple to orange</button></div><div class="gs" id="gs"></div></div>
</div>
<script>
const Pr=[['#1f4fd8','#ffd23f'],['#e5252a','#1f9d55'],['#7b2cbf','#ff8c1a']],c1=document.getElementById('c1'),c2=document.getElementById('c2'),gs=document.getElementById('gs'),bs=[...document.querySelectorAll('#pre button')];let p=0;
const sp=[['sRGB','in srgb','Straight line between the colours; the middle can go grey.'],['HSL','in hsl','Swings around the hue wheel; vivid but sometimes garish.'],['OKLCH','in oklch','Even lightness and chroma; smooth, clean blends.']];
function up(){const ok=CSS.supports('background','linear-gradient(in oklch, red, blue)');gs.innerHTML=sp.map(s=>'<div><b>'+s[0]+'</b><i style="background:'+(ok?'linear-gradient(to right '+s[1]+','+c1.value+','+c2.value+')':'linear-gradient(to right,'+c1.value+','+c2.value+')')+'"></i><small>'+(ok?s[2]:'This browser does not support gradient colour spaces; showing plain sRGB.')+'</small></div>').join('');}
bs.forEach(b=>b.addEventListener('click',()=>{p=+b.dataset.p;c1.value=Pr[p][0];c2.value=Pr[p][1];bs.forEach(k=>k.setAttribute('aria-pressed',String(k===b)));up();}));[c1,c2].forEach(i=>i.addEventListener('input',()=>{bs.forEach(k=>k.setAttribute('aria-pressed','false'));up();}));up();
</script>
</body></html>