Hold to Delete Button
A destructive button that fills while you hold it and only fires when the bar completes; release early to cancel.
AI prompt
Clean UI design of a red hold-to-delete button: a pill-shaped button with the label Hold to delete and a darker red fill covering about sixty percent of it from the left, a small trash icon at the left, below it a short grey hint Keep holding, flat modern style, light theme, subtle shadow. Variants: the empty state, the complete state reading Deleted with an Undo link, and a cancelled state with the fill rewinding. Negative: modal dialogs, heavy gradients, text errors, clutter. Reduced motion: static design.About this pattern
Definition
Hold-to-confirm replaces a confirmation dialog for dangerous actions. The button fills over a fixed time while pressed; letting go early cancels and the fill rewinds. The delay is the confirmation, and it needs no extra screen.
Purpose & UX principles
- Show progress as it fills, and a clear label that says Hold to delete.
- Make the hold time match the risk: about one second for ordinary deletes, two for irreversible ones.
- After completing, show the result and offer Undo where possible.
Interaction states
- A Hold to delete button, three duration presets and an Undo after deleting.
Motion specification
- The fill advances in real time over the chosen duration; releasing early rewinds in 200ms.
- Reduced motion: the fill steps in quarters instead of sliding.
Responsive behaviour
- Keyboard users hold Space or Enter; announce progress at the start and the end, not continuously.
- Provide an alternative for users who cannot hold, such as a confirm dialog in settings.
Code
<div class="bx"><div class="pre" id="pre" role="group" aria-label="Duration"><button data-p="0" aria-pressed="false">Fast 0.8s</button><button data-p="1" aria-pressed="true">Normal 1.2s</button><button data-p="2" aria-pressed="false">Careful 2s</button></div><div class="ar"><button class="hd" id="hd" type="button" aria-describedby="hn"><i class="fl" id="fl"></i><span id="lb">Hold to delete</span></button><button class="mini" id="un" type="button" hidden>Undo</button></div><p class="out" id="hn" role="status">Press and hold. Keyboard: hold Space or Enter.</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}
.ar{display:flex;gap:10px;align-items:center}.hd{position:relative;overflow:hidden;height:46px;padding:0 22px;border-radius:99px;background:#fbe3e1;color:#9d1c1c;font-weight:700;font-size:14px;border:1px solid #f0b8b4;flex:1;touch-action:none;user-select:none}.hd.done{background:#171717;color:#fff;border-color:#171717}.fl{position:absolute;left:0;top:0;bottom:0;width:calc(var(--p)*1%);background:#e5484d;opacity:.9}.hd span{position:relative;z-index:1;mix-blend-mode:normal}.hd.holding span{color:#fff}
.out{font-size:12px;color:var(--muted);margin-top:6px;min-height:18px}.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 D=[800,1200,2000],hd=document.getElementById('hd'),fl=document.getElementById('fl'),lb=document.getElementById('lb'),un=document.getElementById('un'),hn=document.getElementById('hn'),bs=[...document.querySelectorAll('#pre button')],calm=matchMedia('(prefers-reduced-motion:reduce)').matches;let p=1,pr=0,t0=0,id=0,hold=false,done=false;
function paint(){const v=calm?Math.floor(pr/25)*25:pr;fl.style.setProperty('--p',v);hd.classList.toggle('holding',pr>8);}
function loop(now){if(!hold)return;pr=Math.min(100,(now-t0)/D[p]*100);paint();if(pr>=100){fin();return;}id=requestAnimationFrame(loop);}
function begin(){if(done||hold)return;hold=true;t0=performance.now();hn.textContent='Holding\u2026 keep going.';id=requestAnimationFrame(loop);}
function end(){if(!hold)return;hold=false;cancelAnimationFrame(id);if(done)return;hn.textContent='Cancelled. Hold longer to delete.';const s=pr,st=performance.now();(function r(n){const k=Math.min(1,(n-st)/200);pr=s*(1-k);paint();if(k<1&&!hold)requestAnimationFrame(r);})(st);}
function fin(){hold=false;done=true;pr=100;paint();hd.classList.add('done');lb.textContent='Deleted';un.hidden=false;hn.textContent='Item deleted. You can undo.';un.focus();}
hd.addEventListener('pointerdown',e=>{hd.setPointerCapture(e.pointerId);begin();});hd.addEventListener('pointerup',end);hd.addEventListener('pointercancel',end);
hd.addEventListener('keydown',e=>{if((e.key===' '||e.key==='Enter')&&!e.repeat){e.preventDefault();begin();}});hd.addEventListener('keyup',e=>{if(e.key===' '||e.key==='Enter')end();});
un.addEventListener('click',()=>{done=false;pr=0;paint();hd.classList.remove('done');lb.textContent='Hold to delete';un.hidden=true;hn.textContent='Restored.';hd.focus();});
bs.forEach(b=>b.addEventListener('click',()=>{p=+b.dataset.p;bs.forEach(k=>k.setAttribute('aria-pressed',String(k===b)));}));bs[1].setAttribute('aria-pressed','true');bs[0].setAttribute('aria-pressed','false');paint();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>Hold to Delete Button — 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}
.ar{display:flex;gap:10px;align-items:center}.hd{position:relative;overflow:hidden;height:46px;padding:0 22px;border-radius:99px;background:#fbe3e1;color:#9d1c1c;font-weight:700;font-size:14px;border:1px solid #f0b8b4;flex:1;touch-action:none;user-select:none}.hd.done{background:#171717;color:#fff;border-color:#171717}.fl{position:absolute;left:0;top:0;bottom:0;width:calc(var(--p)*1%);background:#e5484d;opacity:.9}.hd span{position:relative;z-index:1;mix-blend-mode:normal}.hd.holding span{color:#fff}
.out{font-size:12px;color:var(--muted);margin-top:6px;min-height:18px}.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"><div class="pre" id="pre" role="group" aria-label="Duration"><button data-p="0" aria-pressed="false">Fast 0.8s</button><button data-p="1" aria-pressed="true">Normal 1.2s</button><button data-p="2" aria-pressed="false">Careful 2s</button></div><div class="ar"><button class="hd" id="hd" type="button" aria-describedby="hn"><i class="fl" id="fl"></i><span id="lb">Hold to delete</span></button><button class="mini" id="un" type="button" hidden>Undo</button></div><p class="out" id="hn" role="status">Press and hold. Keyboard: hold Space or Enter.</p></div>
</div>
<script>
const D=[800,1200,2000],hd=document.getElementById('hd'),fl=document.getElementById('fl'),lb=document.getElementById('lb'),un=document.getElementById('un'),hn=document.getElementById('hn'),bs=[...document.querySelectorAll('#pre button')],calm=matchMedia('(prefers-reduced-motion:reduce)').matches;let p=1,pr=0,t0=0,id=0,hold=false,done=false;
function paint(){const v=calm?Math.floor(pr/25)*25:pr;fl.style.setProperty('--p',v);hd.classList.toggle('holding',pr>8);}
function loop(now){if(!hold)return;pr=Math.min(100,(now-t0)/D[p]*100);paint();if(pr>=100){fin();return;}id=requestAnimationFrame(loop);}
function begin(){if(done||hold)return;hold=true;t0=performance.now();hn.textContent='Holding\u2026 keep going.';id=requestAnimationFrame(loop);}
function end(){if(!hold)return;hold=false;cancelAnimationFrame(id);if(done)return;hn.textContent='Cancelled. Hold longer to delete.';const s=pr,st=performance.now();(function r(n){const k=Math.min(1,(n-st)/200);pr=s*(1-k);paint();if(k<1&&!hold)requestAnimationFrame(r);})(st);}
function fin(){hold=false;done=true;pr=100;paint();hd.classList.add('done');lb.textContent='Deleted';un.hidden=false;hn.textContent='Item deleted. You can undo.';un.focus();}
hd.addEventListener('pointerdown',e=>{hd.setPointerCapture(e.pointerId);begin();});hd.addEventListener('pointerup',end);hd.addEventListener('pointercancel',end);
hd.addEventListener('keydown',e=>{if((e.key===' '||e.key==='Enter')&&!e.repeat){e.preventDefault();begin();}});hd.addEventListener('keyup',e=>{if(e.key===' '||e.key==='Enter')end();});
un.addEventListener('click',()=>{done=false;pr=0;paint();hd.classList.remove('done');lb.textContent='Hold to delete';un.hidden=true;hn.textContent='Restored.';hd.focus();});
bs.forEach(b=>b.addEventListener('click',()=>{p=+b.dataset.p;bs.forEach(k=>k.setAttribute('aria-pressed',String(k===b)));}));bs[1].setAttribute('aria-pressed','true');bs[0].setAttribute('aria-pressed','false');paint();
</script>
</body></html>