Undo Countdown Toast
Delete an item and an undo toast appears with a shrinking timer; hover or focus pauses it and Undo restores the item.
AI prompt
Clean UI mockup of a list of three rows with a bottom-left toast notification that reads Conversation deleted with a bold Undo button and a thin white progress bar along the bottom edge shrinking from right to left, the toast dark charcoal with rounded corners and a soft shadow, one list row visibly missing, light theme, flat modern style. Negative: heavy shadows, clutter, text errors, device frames. Reduced motion: static design with a text countdown.About this pattern
Definition
A better alternative to a confirm dialog is to do the action at once and offer a short Undo. The toast shows what happened, how long the undo window lasts with a shrinking bar, and pauses while the pointer or keyboard focus is on it so nobody loses the chance because they were reading.
Purpose & UX principles
- Act immediately, then show Item deleted with an Undo button for 5 to 8 seconds.
- Show the remaining time as a shrinking bar or ring.
- Pause the timer on hover and focus; resume when they leave.
- If another action happens, stack or replace the toast, and make deletion final only when the toast ends.
Interaction states
- A list of three items; delete one and use Undo within the countdown.
Motion specification
- The bar shrinks over 6 seconds.
- Reduced motion: the bar is replaced by a text countdown.
Responsive behaviour
- Announce the toast to screen readers with role status.
- Make sure the window is long enough; people need time to notice.
Code
<div class="bx"><ul class="ls" id="ls"></ul><div class="to" id="to" role="status" hidden><span id="tt"></span><button class="mini" id="un" type="button">Undo</button><b class="tb"><i id="ti"></i></b></div><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}
.ls{list-style:none;border:1px solid var(--line);border-radius:12px;background:var(--surface);overflow:hidden}.ls li{display:flex;justify-content:space-between;align-items:center;padding:8px 12px;border-bottom:1px solid var(--line);font-size:13px}.ls li:last-child{border:0}.ls button.del{font-size:11.5px;color:#c62f2f;padding:3px 8px;border-radius:6px}.ls button.del:hover{background:rgba(220,50,50,.08)}.to{position:relative;background:#262629;color:#fff;border-radius:10px;padding:10px 12px 12px;display:flex;align-items:center;justify-content:space-between;gap:10px;font-size:12.5px;overflow:hidden;box-shadow:0 6px 16px rgba(0,0,0,.2)}.to[hidden]{display:none}.to .mini{background:transparent;color:#fff;border-color:rgba(255,255,255,.4);height:26px}.tb{position:absolute;left:0;right:0;bottom:0;height:3px;background:rgba(255,255,255,.2)}.tb i{display:block;height:100%;background:#fff;width:100%}.out{font-size:12px;color:var(--muted);min-height:16px}.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){*{transition:none!important;animation:none!important}}const N=['Quarterly report','Team photo','Budget draft'],ls=document.getElementById('ls'),to=document.getElementById('to'),tt=document.getElementById('tt'),ti=document.getElementById('ti'),out=document.getElementById('out'),calm=matchMedia('(prefers-reduced-motion:reduce)').matches,DUR=6000;let items=N.map((n,i)=>({n,i,gone:false})),pend=null,rem=0,last=0,paused=false,raf=0;
function draw(){ls.innerHTML=items.filter(x=>!x.gone).map(x=>'<li><span>'+x.n+'</span><button type="button" class="del" data-i="'+x.i+'" aria-label="Delete '+x.n+'">Delete</button></li>').join('')||'<li><span>No items</span></li>';}
function tick(n){if(!pend)return;if(!paused)rem-=n-last;last=n;const k=Math.max(0,rem/DUR);if(calm)ti.parentNode.hidden=true;else ti.style.width=(k*100)+'%';tt.textContent=pend.n+' deleted'+(calm?' ('+Math.ceil(rem/1000)+' s left)':'');if(rem<=0){pend=null;to.hidden=true;out.textContent='Deletion is now final.';return;}raf=requestAnimationFrame(tick);}
ls.addEventListener('click',e=>{const b=e.target.closest('.del');if(!b)return;if(pend)pend=null;const it=items[+b.dataset.i];it.gone=true;pend=it;rem=DUR;paused=false;last=performance.now();to.hidden=false;draw();out.textContent='';cancelAnimationFrame(raf);raf=requestAnimationFrame(tick);});
document.getElementById('un').addEventListener('click',()=>{if(!pend)return;pend.gone=false;out.textContent=pend.n+' restored.';pend=null;to.hidden=true;draw();});
['mouseenter','focusin'].forEach(t=>to.addEventListener(t,()=>paused=true));['mouseleave','focusout'].forEach(t=>to.addEventListener(t,()=>{paused=false;}));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>Undo Countdown Toast — 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}
.ls{list-style:none;border:1px solid var(--line);border-radius:12px;background:var(--surface);overflow:hidden}.ls li{display:flex;justify-content:space-between;align-items:center;padding:8px 12px;border-bottom:1px solid var(--line);font-size:13px}.ls li:last-child{border:0}.ls button.del{font-size:11.5px;color:#c62f2f;padding:3px 8px;border-radius:6px}.ls button.del:hover{background:rgba(220,50,50,.08)}.to{position:relative;background:#262629;color:#fff;border-radius:10px;padding:10px 12px 12px;display:flex;align-items:center;justify-content:space-between;gap:10px;font-size:12.5px;overflow:hidden;box-shadow:0 6px 16px rgba(0,0,0,.2)}.to[hidden]{display:none}.to .mini{background:transparent;color:#fff;border-color:rgba(255,255,255,.4);height:26px}.tb{position:absolute;left:0;right:0;bottom:0;height:3px;background:rgba(255,255,255,.2)}.tb i{display:block;height:100%;background:#fff;width:100%}.out{font-size:12px;color:var(--muted);min-height:16px}.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){*{transition:none!important;animation:none!important}}
</style></head>
<body><div class="stage">
<div class="bx"><ul class="ls" id="ls"></ul><div class="to" id="to" role="status" hidden><span id="tt"></span><button class="mini" id="un" type="button">Undo</button><b class="tb"><i id="ti"></i></b></div><p class="out" id="out"></p></div>
</div>
<script>
const N=['Quarterly report','Team photo','Budget draft'],ls=document.getElementById('ls'),to=document.getElementById('to'),tt=document.getElementById('tt'),ti=document.getElementById('ti'),out=document.getElementById('out'),calm=matchMedia('(prefers-reduced-motion:reduce)').matches,DUR=6000;let items=N.map((n,i)=>({n,i,gone:false})),pend=null,rem=0,last=0,paused=false,raf=0;
function draw(){ls.innerHTML=items.filter(x=>!x.gone).map(x=>'<li><span>'+x.n+'</span><button type="button" class="del" data-i="'+x.i+'" aria-label="Delete '+x.n+'">Delete</button></li>').join('')||'<li><span>No items</span></li>';}
function tick(n){if(!pend)return;if(!paused)rem-=n-last;last=n;const k=Math.max(0,rem/DUR);if(calm)ti.parentNode.hidden=true;else ti.style.width=(k*100)+'%';tt.textContent=pend.n+' deleted'+(calm?' ('+Math.ceil(rem/1000)+' s left)':'');if(rem<=0){pend=null;to.hidden=true;out.textContent='Deletion is now final.';return;}raf=requestAnimationFrame(tick);}
ls.addEventListener('click',e=>{const b=e.target.closest('.del');if(!b)return;if(pend)pend=null;const it=items[+b.dataset.i];it.gone=true;pend=it;rem=DUR;paused=false;last=performance.now();to.hidden=false;draw();out.textContent='';cancelAnimationFrame(raf);raf=requestAnimationFrame(tick);});
document.getElementById('un').addEventListener('click',()=>{if(!pend)return;pend.gone=false;out.textContent=pend.n+' restored.';pend=null;to.hidden=true;draw();});
['mouseenter','focusin'].forEach(t=>to.addEventListener(t,()=>paused=true));['mouseleave','focusout'].forEach(t=>to.addEventListener(t,()=>{paused=false;}));draw();
</script>
</body></html>