Gradient Banding vs Dither
A dark gradient shown banded, dithered and smooth, with a colour-levels slider.
AI prompt
Close-up comparison of one very subtle dark navy to charcoal gradient shown in three horizontal strips: the first strip with clearly visible stair-step bands of colour, the second strip with a fine dither noise hiding the bands, the third strip perfectly smooth, each labelled Banded, Dithered and Smooth, neutral light background around the strips, flat clean presentation. Negative: extra colours, objects, text errors, heavy grain. Reduced motion: still image.About this pattern
Definition
Smooth gradients on screens are made of a limited number of colour steps. When the colour changes slowly, each step covers many pixels and shows up as visible bands, especially on dark, low-contrast gradients. Adding a tiny amount of noise before the colour is rounded, known as dithering, breaks the edges so the eye sees a smooth ramp.
When to use it
- Banding appears most in dark, subtle gradients and in large flat areas such as backgrounds and skies.
- Dithering adds noise of about one colour step before rounding.
- A fine grain overlay in CSS or an image gives a similar effect.
- Higher bit depth or fewer, bolder colour stops also reduce it.
What the controls do
- Three modes and a Levels slider to coarsen the colour steps.
Motion & timing
- Redraws instantly when you change a control.
- Reduced motion: nothing animates.
Tips & variations
- Heavy noise looks dirty; keep it near one step in strength.
- On exported images, check at 100 percent and on a real display.
Code of this live preview
<div class="bx"><div class="pre" id="pre" role="group" aria-label="Mode"><button data-p="0" aria-pressed="true">Banded</button><button data-p="1" aria-pressed="false">Dithered</button><button data-p="2" aria-pressed="false">Smooth</button></div><canvas id="cv" width="300" height="90" role="img" aria-label="Dark gradient shown with the chosen quantisation mode"></canvas><label class="rw">Colour levels <b id="lv">12</b><input id="ls" type="range" min="4" max="64" value="12"></label><p class="out" id="out"></p></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}
#cv{width:100%;height:96px;border-radius:12px;display:block;background:#222}.out{font-size:12px;color:var(--muted)}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}const cv=document.getElementById('cv'),cx=cv.getContext('2d'),ls=document.getElementById('ls'),bs=[...document.querySelectorAll('#pre button')];let p=0;
function up(){const W=cv.width,H=cv.height,n=+ls.value,img=cx.createImageData(W,H),A=[34,40,58],B=[70,78,108];let s=11;const R=()=>(s=(s*1664525+1013904223)%4294967296)/4294967296;
for(let y=0;y<H;y++)for(let x=0;x<W;x++){const t=x/(W-1),o=(y*W+x)*4;for(let c=0;c<3;c++){let v=A[c]+(B[c]-A[c])*t;if(p===2){}else{const st=255/(n-1);if(p===1)v+=(R()-.5)*st;v=Math.round(v/st)*st;}img.data[o+c]=Math.max(0,Math.min(255,v));}img.data[o+3]=255;}
cx.putImageData(img,0,0);document.getElementById('lv').textContent=n;document.getElementById('out').textContent=p===0?'Visible steps: each band is one colour level.':p===1?'Noise breaks the band edges so the ramp looks smooth.':'Full colour precision: no bands.';ls.disabled=p===2;bs.forEach(b=>b.setAttribute('aria-pressed',String(+b.dataset.p===p)));}
bs.forEach(b=>b.addEventListener('click',()=>{p=+b.dataset.p;up();}));ls.addEventListener('input',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 Banding vs Dither — 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}
#cv{width:100%;height:96px;border-radius:12px;display:block;background:#222}.out{font-size:12px;color:var(--muted)}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
</style></head>
<body><div class="stage">
<div class="bx"><div class="pre" id="pre" role="group" aria-label="Mode"><button data-p="0" aria-pressed="true">Banded</button><button data-p="1" aria-pressed="false">Dithered</button><button data-p="2" aria-pressed="false">Smooth</button></div><canvas id="cv" width="300" height="90" role="img" aria-label="Dark gradient shown with the chosen quantisation mode"></canvas><label class="rw">Colour levels <b id="lv">12</b><input id="ls" type="range" min="4" max="64" value="12"></label><p class="out" id="out"></p></div>
</div>
<script>
const cv=document.getElementById('cv'),cx=cv.getContext('2d'),ls=document.getElementById('ls'),bs=[...document.querySelectorAll('#pre button')];let p=0;
function up(){const W=cv.width,H=cv.height,n=+ls.value,img=cx.createImageData(W,H),A=[34,40,58],B=[70,78,108];let s=11;const R=()=>(s=(s*1664525+1013904223)%4294967296)/4294967296;
for(let y=0;y<H;y++)for(let x=0;x<W;x++){const t=x/(W-1),o=(y*W+x)*4;for(let c=0;c<3;c++){let v=A[c]+(B[c]-A[c])*t;if(p===2){}else{const st=255/(n-1);if(p===1)v+=(R()-.5)*st;v=Math.round(v/st)*st;}img.data[o+c]=Math.max(0,Math.min(255,v));}img.data[o+3]=255;}
cx.putImageData(img,0,0);document.getElementById('lv').textContent=n;document.getElementById('out').textContent=p===0?'Visible steps: each band is one colour level.':p===1?'Noise breaks the band edges so the ramp looks smooth.':'Full colour precision: no bands.';ls.disabled=p===2;bs.forEach(b=>b.setAttribute('aria-pressed',String(+b.dataset.p===p)));}
bs.forEach(b=>b.addEventListener('click',()=>{p=+b.dataset.p;up();}));ls.addEventListener('input',up);up();
</script>
</body></html>