Waterfall Change Chart
A waterfall chart that bridges a start value to an end value through increases and decreases, with hover details.
AI prompt
Clean waterfall chart of annual profit, a dark blue start bar Last year 120, then a green floating bar Sales plus 45, a red floating bar Costs minus 30, a green bar Pricing plus 25, a red bar Tax minus 15, and a dark blue end bar This year 145, thin grey connector lines between bars, signed value labels above each bar, faint horizontal grid lines, flat vector style, clear and calm. Negative: 3D, gradients, rainbow colours, text errors, clutter. Reduced motion: static chart.About this pattern
Definition
A waterfall chart explains how you got from one total to another. Floating bars show each increase or decrease stacked on the running total, so you can see which items added and which took away. It is the standard chart for profit bridges, budgets and variance explanations.
Purpose & UX principles
- Start and end bars sit on the baseline; change bars float between running totals.
- Colour increases and decreases differently and also mark them with a plus or minus sign.
- Connect bars with thin lines so the running total is easy to follow.
- Label the bars and show the value above or below each.
Interaction states
- Two datasets; hover, focus or tap a bar for its detail.
Motion specification
- Bars grow upward in sequence over 600ms on change.
- Reduced motion: bars appear at once.
Responsive behaviour
- Do not use colour alone: include signs and text labels.
- Provide the numbers in a table for people who need exact values.
Code
<div class="bx"><div class="pre" id="pre" role="group" aria-label="Data"><button data-p="0" aria-pressed="true">Profit</button><button data-p="1" aria-pressed="false">Users</button></div><svg class="wf" id="wf" viewBox="0 0 330 150" role="group" aria-label="Waterfall chart"></svg><p class="out" id="out" role="status"></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}
.wf{width:100%;height:auto;border:1px solid var(--line);border-radius:12px;background:#fff}.wf g.b{cursor:pointer}.wf rect{transition:y .5s,height .5s}.wf text{font:10px system-ui,sans-serif;fill:#555}.wf .v{font-weight:700;fill:#171717}.wf g.b:hover rect,.wf g.b:focus rect{stroke:#171717;stroke-width:1.5}.out{font-size:12px;color:var(--muted);min-height:16px}@media (prefers-reduced-motion:reduce){.wf rect{transition:none}}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}const D=[[['Last year',120,'t'],['Sales',45],['Costs',-30],['Pricing',25],['Tax',-15],['This year',0,'t']],[['Jan users',800,'t'],['New',420],['Churned',-180],['Invites',150],['Returns',60],['Now',0,'t']]],wf=document.getElementById('wf'),bs=[...document.querySelectorAll('#pre button')],out=document.getElementById('out');let p=0;
function up(){const raw=D[p].map(x=>x.slice());let run=0;raw.forEach(x=>{if(x[2]==='t'){if(x[1]===0)x[1]=run;run=x[1];}else run+=x[1];});const mx=Math.max(...raw.map(x=>x[2]==='t'?x[1]:0),...(()=>{let r=0,m=0;D[p].forEach(x=>{if(x[2]==='t')r=x[1]||r;else r+=x[1];m=Math.max(m,r);});return[m];})())*1.12;
const W=330,H=150,pl=14,pb=22,pt=12,n=raw.length,bw=(W-pl*2)/n,y=v=>H-pb-(v/mx)*(H-pb-pt);let run2=0,html='';[0,.5,1].forEach(g=>{html+='<line x1="'+pl+'" x2="'+(W-pl)+'" y1="'+y(mx*g/1.12)+'" y2="'+y(mx*g/1.12)+'" stroke="#eee"/>';});
raw.forEach((x,i)=>{let top,bot,col;if(x[2]==='t'){top=x[1];bot=0;col='#1f3a8a';run2=x[1];}else{const a=run2,b=run2+x[1];top=Math.max(a,b);bot=Math.min(a,b);col=x[1]>=0?'#2e9e4f':'#d33';run2=b;}
const x0=pl+i*bw+bw*.16,w=bw*.68,val=(x[2]==='t'?x[1]:(x[1]>0?'+':'\u2212')+Math.abs(x[1]));html+='<g class="b" tabindex="0" data-i="'+i+'" aria-label="'+x[0]+': '+val+'"><rect x="'+x0+'" y="'+y(top)+'" width="'+w+'" height="'+Math.max(2,y(bot)-y(top))+'" rx="2" fill="'+col+'"/><text class="v" x="'+(x0+w/2)+'" y="'+(y(top)-3)+'" text-anchor="middle">'+val+'</text><text x="'+(x0+w/2)+'" y="'+(H-8)+'" text-anchor="middle">'+x[0]+'</text></g>';if(i<n-1)html+='<line x1="'+(x0+w)+'" x2="'+(x0+w+bw*.32)+'" y1="'+y(run2)+'" y2="'+y(run2)+'" stroke="#bbb" stroke-dasharray="2 2"/>';});
wf.innerHTML=html;wf.querySelectorAll('.b').forEach(g=>{const i=+g.dataset.i,show=()=>{const x=raw[i];out.textContent=x[2]==='t'?x[0]+': total '+x[1]+'.':x[0]+': '+(x[1]>0?'increases':'decreases')+' the total by '+Math.abs(x[1])+'.';};g.addEventListener('mouseenter',show);g.addEventListener('focus',show);g.addEventListener('click',show);});out.textContent='Hover, focus or tap a bar.';bs.forEach(b=>b.setAttribute('aria-pressed',String(+b.dataset.p===p)));}
bs.forEach(b=>b.addEventListener('click',()=>{p=+b.dataset.p;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>Waterfall Change Chart — 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}
.wf{width:100%;height:auto;border:1px solid var(--line);border-radius:12px;background:#fff}.wf g.b{cursor:pointer}.wf rect{transition:y .5s,height .5s}.wf text{font:10px system-ui,sans-serif;fill:#555}.wf .v{font-weight:700;fill:#171717}.wf g.b:hover rect,.wf g.b:focus rect{stroke:#171717;stroke-width:1.5}.out{font-size:12px;color:var(--muted);min-height:16px}@media (prefers-reduced-motion:reduce){.wf rect{transition:none}}
@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="Data"><button data-p="0" aria-pressed="true">Profit</button><button data-p="1" aria-pressed="false">Users</button></div><svg class="wf" id="wf" viewBox="0 0 330 150" role="group" aria-label="Waterfall chart"></svg><p class="out" id="out" role="status"></p></div>
</div>
<script>
const D=[[['Last year',120,'t'],['Sales',45],['Costs',-30],['Pricing',25],['Tax',-15],['This year',0,'t']],[['Jan users',800,'t'],['New',420],['Churned',-180],['Invites',150],['Returns',60],['Now',0,'t']]],wf=document.getElementById('wf'),bs=[...document.querySelectorAll('#pre button')],out=document.getElementById('out');let p=0;
function up(){const raw=D[p].map(x=>x.slice());let run=0;raw.forEach(x=>{if(x[2]==='t'){if(x[1]===0)x[1]=run;run=x[1];}else run+=x[1];});const mx=Math.max(...raw.map(x=>x[2]==='t'?x[1]:0),...(()=>{let r=0,m=0;D[p].forEach(x=>{if(x[2]==='t')r=x[1]||r;else r+=x[1];m=Math.max(m,r);});return[m];})())*1.12;
const W=330,H=150,pl=14,pb=22,pt=12,n=raw.length,bw=(W-pl*2)/n,y=v=>H-pb-(v/mx)*(H-pb-pt);let run2=0,html='';[0,.5,1].forEach(g=>{html+='<line x1="'+pl+'" x2="'+(W-pl)+'" y1="'+y(mx*g/1.12)+'" y2="'+y(mx*g/1.12)+'" stroke="#eee"/>';});
raw.forEach((x,i)=>{let top,bot,col;if(x[2]==='t'){top=x[1];bot=0;col='#1f3a8a';run2=x[1];}else{const a=run2,b=run2+x[1];top=Math.max(a,b);bot=Math.min(a,b);col=x[1]>=0?'#2e9e4f':'#d33';run2=b;}
const x0=pl+i*bw+bw*.16,w=bw*.68,val=(x[2]==='t'?x[1]:(x[1]>0?'+':'\u2212')+Math.abs(x[1]));html+='<g class="b" tabindex="0" data-i="'+i+'" aria-label="'+x[0]+': '+val+'"><rect x="'+x0+'" y="'+y(top)+'" width="'+w+'" height="'+Math.max(2,y(bot)-y(top))+'" rx="2" fill="'+col+'"/><text class="v" x="'+(x0+w/2)+'" y="'+(y(top)-3)+'" text-anchor="middle">'+val+'</text><text x="'+(x0+w/2)+'" y="'+(H-8)+'" text-anchor="middle">'+x[0]+'</text></g>';if(i<n-1)html+='<line x1="'+(x0+w)+'" x2="'+(x0+w+bw*.32)+'" y1="'+y(run2)+'" y2="'+y(run2)+'" stroke="#bbb" stroke-dasharray="2 2"/>';});
wf.innerHTML=html;wf.querySelectorAll('.b').forEach(g=>{const i=+g.dataset.i,show=()=>{const x=raw[i];out.textContent=x[2]==='t'?x[0]+': total '+x[1]+'.':x[0]+': '+(x[1]>0?'increases':'decreases')+' the total by '+Math.abs(x[1])+'.';};g.addEventListener('mouseenter',show);g.addEventListener('focus',show);g.addEventListener('click',show);});out.textContent='Hover, focus or tap a bar.';bs.forEach(b=>b.setAttribute('aria-pressed',String(+b.dataset.p===p)));}
bs.forEach(b=>b.addEventListener('click',()=>{p=+b.dataset.p;up();}));up();
</script>
</body></html>