Progress Indicator
Linear and circular determinate progress with a readable percentage.
AI prompt
Build a determinate progress indicator with two views of the same value: a linear bar (8px tall, rounded) and a circular ring (96px, SVG circle with stroke-dasharray and stroke-dashoffset). Both are driven by one JS value from 0 to 100. Provide a "Start upload" button that advances progress with irregular steps (like a real upload) until 100, and a "Reset" button. The bar and ring use role="progressbar" with aria-valuenow, aria-valuemin 0, aria-valuemax 100 and an aria-label. A text readout shows the percentage in tabular digits. Width and offset transition 200ms linear. On completion the colour stays accent, a check icon replaces the number in the ring with a 240ms pop. Under prefers-reduced-motion remove transitions and the pop.About this pattern
Definition
A visual that shows how much of a known task is complete. This page shows a linear bar and a circular ring driven by the same value, both announced to assistive technology.
Purpose & UX principles
- Use when the duration or amount is known (uploads, multi-step tasks). Use a spinner when it is not.
- Show the number as well as the shape; people want to know "how long".
- Never let it go backwards or stall at 99% without explanation; if the real progress is unknown, show an indeterminate state.
Interaction states
- Idle (0%), running, complete (check icon and accent colour), error (red, with a retry).
- Uses
role="progressbar"witharia-valuenow,aria-valueminandaria-valuemax.
Motion specification
- Bar width and ring offset follow the value with a 200ms linear transition so jumps look continuous.
- Completion: a 240ms scale pop on the check icon.
- Reduced motion: no transition and no pop.
Responsive behaviour
- The bar fills its container; the ring keeps a fixed size (96px) and the percentage stays centred in it.
Code
<div class="box">
<div class="top"><span>Uploading design.zip</span><b id="pct">0%</b></div>
<div class="bar" role="progressbar" aria-label="Upload progress" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0" id="bar"><i id="fill"></i></div>
<div class="ringwrap"><svg viewBox="0 0 100 100" width="96" height="96" role="progressbar" aria-label="Upload progress ring" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0" id="ring"><circle cx="50" cy="50" r="42" class="bg"/><circle cx="50" cy="50" r="42" class="fg" id="fg"/></svg><span id="mid">0</span></div>
<div class="ctl"><button id="start">Start upload</button><button id="reset">Reset</button></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}
.box{width:min(360px,100%);padding:22px;border:1px solid var(--line);border-radius:18px;background:var(--surface);display:grid;gap:18px;justify-items:stretch}
.top{display:flex;justify-content:space-between;font-size:14px}.top b{font-variant-numeric:tabular-nums;color:var(--accent)}
.bar{height:8px;border-radius:4px;background:var(--surface-2);overflow:hidden}
.bar i{display:block;height:100%;width:0;background:var(--accent);border-radius:4px;transition:width .2s linear}
.ringwrap{position:relative;width:96px;height:96px;justify-self:center}
.ringwrap svg{transform:rotate(-90deg)}
.bg,.fg{fill:none;stroke-width:8}.bg{stroke:var(--surface-2)}
.fg{stroke:var(--accent);stroke-linecap:round;stroke-dasharray:264;stroke-dashoffset:264;transition:stroke-dashoffset .2s linear}
.ringwrap span{position:absolute;inset:0;display:grid;place-items:center;font-size:20px;font-weight:700;font-variant-numeric:tabular-nums}
.ringwrap span.done{animation:pop .24s cubic-bezier(.3,1.6,.5,1);color:var(--accent);font-size:30px}
.ctl{display:flex;gap:8px;justify-content:center}
.ctl button{height:38px;padding:0 16px;border-radius:10px;border:1px solid var(--line);background:var(--surface-2);color:var(--text);font:inherit;font-weight:600;cursor:pointer}
.ctl button:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
@keyframes pop{from{transform:scale(.5)}}
@media (prefers-reduced-motion:reduce){.bar i,.fg{transition:none}.ringwrap span.done{animation:none}}const $=id=>document.getElementById(id);let v=0,t;
function set(n){v=Math.min(100,n);const r=Math.round(v);
$('fill').style.width=v+'%';$('fg').style.strokeDashoffset=264*(1-v/100);$('pct').textContent=r+'%';
$('bar').setAttribute('aria-valuenow',r);$('ring').setAttribute('aria-valuenow',r);
const m=$('mid');if(v>=100){m.textContent='✓';m.className='done';}else{m.textContent=r;m.className='';}}
function tick(){if(v>=100)return;set(v+Math.random()*9+1);t=setTimeout(tick,120+Math.random()*260);}
$('start').onclick=()=>{clearTimeout(t);set(0);tick();};
$('reset').onclick=()=>{clearTimeout(t);set(0);};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>Progress Indicator — 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}}
.box{width:min(360px,100%);padding:22px;border:1px solid var(--line);border-radius:18px;background:var(--surface);display:grid;gap:18px;justify-items:stretch}
.top{display:flex;justify-content:space-between;font-size:14px}.top b{font-variant-numeric:tabular-nums;color:var(--accent)}
.bar{height:8px;border-radius:4px;background:var(--surface-2);overflow:hidden}
.bar i{display:block;height:100%;width:0;background:var(--accent);border-radius:4px;transition:width .2s linear}
.ringwrap{position:relative;width:96px;height:96px;justify-self:center}
.ringwrap svg{transform:rotate(-90deg)}
.bg,.fg{fill:none;stroke-width:8}.bg{stroke:var(--surface-2)}
.fg{stroke:var(--accent);stroke-linecap:round;stroke-dasharray:264;stroke-dashoffset:264;transition:stroke-dashoffset .2s linear}
.ringwrap span{position:absolute;inset:0;display:grid;place-items:center;font-size:20px;font-weight:700;font-variant-numeric:tabular-nums}
.ringwrap span.done{animation:pop .24s cubic-bezier(.3,1.6,.5,1);color:var(--accent);font-size:30px}
.ctl{display:flex;gap:8px;justify-content:center}
.ctl button{height:38px;padding:0 16px;border-radius:10px;border:1px solid var(--line);background:var(--surface-2);color:var(--text);font:inherit;font-weight:600;cursor:pointer}
.ctl button:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
@keyframes pop{from{transform:scale(.5)}}
@media (prefers-reduced-motion:reduce){.bar i,.fg{transition:none}.ringwrap span.done{animation:none}}
</style></head>
<body><div class="stage">
<div class="box">
<div class="top"><span>Uploading design.zip</span><b id="pct">0%</b></div>
<div class="bar" role="progressbar" aria-label="Upload progress" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0" id="bar"><i id="fill"></i></div>
<div class="ringwrap"><svg viewBox="0 0 100 100" width="96" height="96" role="progressbar" aria-label="Upload progress ring" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0" id="ring"><circle cx="50" cy="50" r="42" class="bg"/><circle cx="50" cy="50" r="42" class="fg" id="fg"/></svg><span id="mid">0</span></div>
<div class="ctl"><button id="start">Start upload</button><button id="reset">Reset</button></div>
</div>
</div>
<script>
const $=id=>document.getElementById(id);let v=0,t;
function set(n){v=Math.min(100,n);const r=Math.round(v);
$('fill').style.width=v+'%';$('fg').style.strokeDashoffset=264*(1-v/100);$('pct').textContent=r+'%';
$('bar').setAttribute('aria-valuenow',r);$('ring').setAttribute('aria-valuenow',r);
const m=$('mid');if(v>=100){m.textContent='✓';m.className='done';}else{m.textContent=r;m.className='';}}
function tick(){if(v>=100)return;set(v+Math.random()*9+1);t=setTimeout(tick,120+Math.random()*260);}
$('start').onclick=()=>{clearTimeout(t);set(0);tick();};
$('reset').onclick=()=>{clearTimeout(t);set(0);};
</script>
</body></html>