Countdown Timer Ring
A circular countdown with presets, start, pause and reset, whose ring empties as time runs down.
AI prompt
Clean UI mockup of a circular countdown timer, a thick light grey ring with a blue arc covering about 40 percent draining clockwise from the top, the large digits 00:12 in the centre with the small label seconds left, three small preset chips 10 s, 30 s, 1 min below and round Start and Reset buttons, light theme, flat modern style. Variant: the finished state with a full green ring and a check mark. Negative: heavy gradients, 3D, clutter, text errors. Reduced motion: static design.About this pattern
Definition
A ring timer shows time left as a circle that empties, with the digits in the middle. It is quick to read at a glance. The ring is an SVG circle whose stroke-dashoffset follows the remaining fraction, and the digits give the exact time for precision and for assistive technology.
Purpose & UX principles
- Use pathLength 1 on the circle so the offset equals the fraction elapsed.
- Rotate the circle so it starts at the top and drains clockwise.
- Update from timestamps (performance.now), not by counting intervals, so it stays accurate when the tab is throttled.
- At zero, show a clear finished state and keep it until reset.
Interaction states
- Presets 10 s, 30 s and 1 min; Start, Pause and Reset.
Motion specification
- The ring drains smoothly; at the end the ring pulses once.
- Reduced motion: no pulse and the ring updates once per second.
Responsive behaviour
- Give the container role timer and do not announce every second; announce only at the end.
- Provide Pause and Reset as real buttons.
Code
<div class="bx"><div class="pre" id="pre" role="group" aria-label="Duration"><button data-p="0" aria-pressed="true">10 s</button><button data-p="1" aria-pressed="false">30 s</button><button data-p="2" aria-pressed="false">1 min</button></div><div class="tm" id="tm" role="timer" aria-label="Countdown"><svg viewBox="0 0 120 120" aria-hidden="true"><circle cx="60" cy="60" r="50" fill="none" stroke="#e6e6e2" stroke-width="10"/><circle id="rg" cx="60" cy="60" r="50" fill="none" stroke="#2f6bff" stroke-width="10" stroke-linecap="round" pathLength="1" stroke-dasharray="1" stroke-dashoffset="0" transform="rotate(-90 60 60)"/></svg><b id="dg">00:10</b></div><div class="two"><button class="mini" id="go" type="button">Start</button><button class="mini" id="rs" type="button">Reset</button></div><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}
.tm{position:relative;width:128px;height:128px;margin:0 auto}.tm svg{width:100%;height:100%}.tm b{position:absolute;inset:0;display:grid;place-items:center;font:700 26px ui-monospace,Menlo,monospace}.tm.fin{animation:pu .5s}.tm.fin #rg{stroke:#1f9d55}@keyframes pu{50%{transform:scale(1.07)}}.out{font-size:12px;color:var(--muted);min-height:16px;text-align:center}.two{display:grid;grid-template-columns:1fr 1fr;gap:12px}.mini{height:30px;padding:0 14px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:12px;font-weight:600;cursor:pointer}.mini:disabled{opacity:.4;cursor:default}@media (prefers-reduced-motion:reduce){.tm.fin{animation:none}}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}const D=[10,30,60],rg=document.getElementById('rg'),dg=document.getElementById('dg'),tm=document.getElementById('tm'),go=document.getElementById('go'),out=document.getElementById('out'),bs=[...document.querySelectorAll('#pre button')],calm=matchMedia('(prefers-reduced-motion:reduce)').matches;let p=0,rem=D[0]*1000,run=false,last=0,raf=0;
const f=ms=>{const s=Math.ceil(ms/1000);return String(Math.floor(s/60)).padStart(2,'0')+':'+String(s%60).padStart(2,'0');};
function draw(){const k=1-rem/(D[p]*1000);rg.setAttribute('stroke-dashoffset',calm?(1-Math.ceil(rem/1000)/D[p]):k);rg.style.strokeDashoffset=calm?(1-Math.ceil(rem/1000)/D[p]):k;dg.textContent=f(rem);}
function tick(n){if(!run)return;rem=Math.max(0,rem-(n-last));last=n;draw();if(rem<=0){run=false;tm.classList.add('fin');rg.style.strokeDashoffset=0;rg.setAttribute('stroke-dashoffset',0);go.textContent='Start';out.textContent='Time is up.';return;}raf=requestAnimationFrame(tick);}
function reset(){run=false;cancelAnimationFrame(raf);rem=D[p]*1000;tm.classList.remove('fin');go.textContent='Start';out.textContent='';draw();}
go.addEventListener('click',()=>{if(run){run=false;go.textContent='Resume';out.textContent='Paused.';return;}if(rem<=0)reset();tm.classList.remove('fin');run=true;go.textContent='Pause';out.textContent='';last=performance.now();raf=requestAnimationFrame(tick);});
document.getElementById('rs').addEventListener('click',reset);bs.forEach(b=>b.addEventListener('click',()=>{p=+b.dataset.p;bs.forEach(k=>k.setAttribute('aria-pressed',String(k===b)));reset();}));draw();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>Countdown Timer Ring — 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}
.tm{position:relative;width:128px;height:128px;margin:0 auto}.tm svg{width:100%;height:100%}.tm b{position:absolute;inset:0;display:grid;place-items:center;font:700 26px ui-monospace,Menlo,monospace}.tm.fin{animation:pu .5s}.tm.fin #rg{stroke:#1f9d55}@keyframes pu{50%{transform:scale(1.07)}}.out{font-size:12px;color:var(--muted);min-height:16px;text-align:center}.two{display:grid;grid-template-columns:1fr 1fr;gap:12px}.mini{height:30px;padding:0 14px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:12px;font-weight:600;cursor:pointer}.mini:disabled{opacity:.4;cursor:default}@media (prefers-reduced-motion:reduce){.tm.fin{animation: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="Duration"><button data-p="0" aria-pressed="true">10 s</button><button data-p="1" aria-pressed="false">30 s</button><button data-p="2" aria-pressed="false">1 min</button></div><div class="tm" id="tm" role="timer" aria-label="Countdown"><svg viewBox="0 0 120 120" aria-hidden="true"><circle cx="60" cy="60" r="50" fill="none" stroke="#e6e6e2" stroke-width="10"/><circle id="rg" cx="60" cy="60" r="50" fill="none" stroke="#2f6bff" stroke-width="10" stroke-linecap="round" pathLength="1" stroke-dasharray="1" stroke-dashoffset="0" transform="rotate(-90 60 60)"/></svg><b id="dg">00:10</b></div><div class="two"><button class="mini" id="go" type="button">Start</button><button class="mini" id="rs" type="button">Reset</button></div><p class="out" id="out" role="status"></p></div>
</div>
<script>
const D=[10,30,60],rg=document.getElementById('rg'),dg=document.getElementById('dg'),tm=document.getElementById('tm'),go=document.getElementById('go'),out=document.getElementById('out'),bs=[...document.querySelectorAll('#pre button')],calm=matchMedia('(prefers-reduced-motion:reduce)').matches;let p=0,rem=D[0]*1000,run=false,last=0,raf=0;
const f=ms=>{const s=Math.ceil(ms/1000);return String(Math.floor(s/60)).padStart(2,'0')+':'+String(s%60).padStart(2,'0');};
function draw(){const k=1-rem/(D[p]*1000);rg.setAttribute('stroke-dashoffset',calm?(1-Math.ceil(rem/1000)/D[p]):k);rg.style.strokeDashoffset=calm?(1-Math.ceil(rem/1000)/D[p]):k;dg.textContent=f(rem);}
function tick(n){if(!run)return;rem=Math.max(0,rem-(n-last));last=n;draw();if(rem<=0){run=false;tm.classList.add('fin');rg.style.strokeDashoffset=0;rg.setAttribute('stroke-dashoffset',0);go.textContent='Start';out.textContent='Time is up.';return;}raf=requestAnimationFrame(tick);}
function reset(){run=false;cancelAnimationFrame(raf);rem=D[p]*1000;tm.classList.remove('fin');go.textContent='Start';out.textContent='';draw();}
go.addEventListener('click',()=>{if(run){run=false;go.textContent='Resume';out.textContent='Paused.';return;}if(rem<=0)reset();tm.classList.remove('fin');run=true;go.textContent='Pause';out.textContent='';last=performance.now();raf=requestAnimationFrame(tick);});
document.getElementById('rs').addEventListener('click',reset);bs.forEach(b=>b.addEventListener('click',()=>{p=+b.dataset.p;bs.forEach(k=>k.setAttribute('aria-pressed',String(k===b)));reset();}));draw();
</script>
</body></html>