Type-to-Confirm Delete
A destructive dialog where the confirm button unlocks only after you type the exact phrase.
AI prompt
Design an alert dialog for deleting a project called "Atlas". Title "Delete project Atlas?", body "This permanently deletes 48 files and cannot be undone." A labelled text input asks the user to type "delete atlas" to confirm; the red "Delete project" button stays disabled until the input matches exactly (case-insensitive). A neutral Cancel button sits to its left. Use role alertdialog with aria-labelledby and aria-describedby, move focus to the input on open, trap Tab inside, close on Escape and return focus to the trigger button. Light backdrop blur, 14 pixel radius, minimal styling, 180 millisecond scale-fade entry with prefers-reduced-motion fallback. Plain HTML, CSS, JavaScript.About this pattern
Definition
A type-to-confirm dialog adds friction to irreversible actions. The danger button stays disabled until the person types a specific phrase, which prevents accidental clicks.
Purpose & UX principles
- Use it only for destructive, hard-to-undo actions such as deleting a project; for reversible actions prefer undo.
- Name what will be lost, state that it cannot be undone and show the exact phrase to type.
- Focus starts on the input; Escape and Cancel close safely; focus returns to the opener.
Interaction states
- Closed, open with confirm disabled, open with matching text (confirm enabled), deleted result.
Motion specification
- Dialog fades and scales from 0.96 over 180ms; backdrop fades over 180ms.
- Reduced motion: no scale, instant fade.
Responsive behaviour
- Dialog is up to 360px wide and centred; on phones it fills the width with 16px margins.
- Buttons stack on very narrow screens, with the safe action first.
Code
<div class="bx"><button class="trig" id="trig" type="button">Delete project…</button><p class="res" id="res" aria-live="polite">Project "Atlas" is active.</p>
<div class="bk" id="bk" hidden><div class="dlg" id="dlg" role="alertdialog" aria-modal="true" aria-labelledby="t" aria-describedby="d"><h2 id="t">Delete project Atlas?</h2><p id="d">This permanently deletes 48 files and cannot be undone.</p><label><span>Type <b>delete atlas</b> to confirm</span><input id="in" autocomplete="off"></label><div class="bt"><button id="cn" type="button">Cancel</button><button id="ok" type="button" disabled>Delete project</button></div></div></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}
.bx{position:relative;width:min(300px,100%);display:grid;gap:10px;justify-items:start}
.trig{height:34px;padding:0 16px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:13px;cursor:pointer;color:var(--danger);font-weight:600}
.res{font-size:12.5px;color:var(--muted)}
.bk{position:fixed;inset:0;background:rgba(241,241,239,.7);-webkit-backdrop-filter:blur(3px);backdrop-filter:blur(3px);display:grid;place-items:center;padding:12px;animation:fi .18s ease-out}
.bk[hidden]{display:none}
.dlg{width:min(300px,100%);padding:16px;border-radius:14px;background:var(--surface);border:1px solid var(--line);box-shadow:0 14px 40px rgba(0,0,0,.14);animation:sc .18s ease-out}
@keyframes fi{from{opacity:0}}@keyframes sc{from{opacity:0;transform:scale(.96)}}
.dlg h2{font-size:15px;margin-bottom:4px}.dlg p{font-size:12.5px;color:var(--muted);margin-bottom:10px}
.dlg label{display:grid;gap:5px;font-size:12px;color:var(--muted)}.dlg b{color:var(--text)}
.dlg input{height:34px;border:1px solid var(--line);border-radius:8px;padding:0 10px;font-size:13px}
.dlg input:focus{outline:2px solid var(--accent);outline-offset:1px}
.bt{display:flex;justify-content:flex-end;gap:6px;margin-top:12px}.bt button{height:32px;padding:0 14px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:12.5px;cursor:pointer}
#ok{background:var(--danger);border-color:var(--danger);color:#fff;font-weight:600}#ok:disabled{opacity:.35;cursor:not-allowed}
button:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
@media (prefers-reduced-motion:reduce){.bk,.dlg{animation:none}}const $=id=>document.getElementById(id),trig=$('trig'),bk=$('bk'),inp=$('in'),ok=$('ok'),cn=$('cn'),res=$('res');
function open(){bk.hidden=false;inp.value='';ok.disabled=true;inp.focus();}
function close(){bk.hidden=true;trig.focus();}
trig.addEventListener('click',open);cn.addEventListener('click',close);
inp.addEventListener('input',()=>{ok.disabled=inp.value.trim().toLowerCase()!=='delete atlas';});
ok.addEventListener('click',()=>{bk.hidden=true;res.textContent='Project "Atlas" deleted.';trig.disabled=true;trig.style.opacity='.4';setTimeout(()=>{trig.disabled=false;trig.style.opacity='';res.textContent='Project "Atlas" is active.';},2500);});
bk.addEventListener('keydown',e=>{if(e.key==='Escape'){e.preventDefault();close();}else if(e.key==='Tab'){const f=[inp,cn,ok].filter(x=>!x.disabled),i=f.indexOf(document.activeElement);e.preventDefault();f[(i+(e.shiftKey?-1:1)+f.length)%f.length].focus();}});
bk.addEventListener('pointerdown',e=>{if(e.target===bk)close();});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>Type-to-Confirm Delete — 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}}
.bx{position:relative;width:min(300px,100%);display:grid;gap:10px;justify-items:start}
.trig{height:34px;padding:0 16px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:13px;cursor:pointer;color:var(--danger);font-weight:600}
.res{font-size:12.5px;color:var(--muted)}
.bk{position:fixed;inset:0;background:rgba(241,241,239,.7);-webkit-backdrop-filter:blur(3px);backdrop-filter:blur(3px);display:grid;place-items:center;padding:12px;animation:fi .18s ease-out}
.bk[hidden]{display:none}
.dlg{width:min(300px,100%);padding:16px;border-radius:14px;background:var(--surface);border:1px solid var(--line);box-shadow:0 14px 40px rgba(0,0,0,.14);animation:sc .18s ease-out}
@keyframes fi{from{opacity:0}}@keyframes sc{from{opacity:0;transform:scale(.96)}}
.dlg h2{font-size:15px;margin-bottom:4px}.dlg p{font-size:12.5px;color:var(--muted);margin-bottom:10px}
.dlg label{display:grid;gap:5px;font-size:12px;color:var(--muted)}.dlg b{color:var(--text)}
.dlg input{height:34px;border:1px solid var(--line);border-radius:8px;padding:0 10px;font-size:13px}
.dlg input:focus{outline:2px solid var(--accent);outline-offset:1px}
.bt{display:flex;justify-content:flex-end;gap:6px;margin-top:12px}.bt button{height:32px;padding:0 14px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:12.5px;cursor:pointer}
#ok{background:var(--danger);border-color:var(--danger);color:#fff;font-weight:600}#ok:disabled{opacity:.35;cursor:not-allowed}
button:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
@media (prefers-reduced-motion:reduce){.bk,.dlg{animation:none}}
</style></head>
<body><div class="stage">
<div class="bx"><button class="trig" id="trig" type="button">Delete project…</button><p class="res" id="res" aria-live="polite">Project "Atlas" is active.</p>
<div class="bk" id="bk" hidden><div class="dlg" id="dlg" role="alertdialog" aria-modal="true" aria-labelledby="t" aria-describedby="d"><h2 id="t">Delete project Atlas?</h2><p id="d">This permanently deletes 48 files and cannot be undone.</p><label><span>Type <b>delete atlas</b> to confirm</span><input id="in" autocomplete="off"></label><div class="bt"><button id="cn" type="button">Cancel</button><button id="ok" type="button" disabled>Delete project</button></div></div></div></div>
</div>
<script>
const $=id=>document.getElementById(id),trig=$('trig'),bk=$('bk'),inp=$('in'),ok=$('ok'),cn=$('cn'),res=$('res');
function open(){bk.hidden=false;inp.value='';ok.disabled=true;inp.focus();}
function close(){bk.hidden=true;trig.focus();}
trig.addEventListener('click',open);cn.addEventListener('click',close);
inp.addEventListener('input',()=>{ok.disabled=inp.value.trim().toLowerCase()!=='delete atlas';});
ok.addEventListener('click',()=>{bk.hidden=true;res.textContent='Project "Atlas" deleted.';trig.disabled=true;trig.style.opacity='.4';setTimeout(()=>{trig.disabled=false;trig.style.opacity='';res.textContent='Project "Atlas" is active.';},2500);});
bk.addEventListener('keydown',e=>{if(e.key==='Escape'){e.preventDefault();close();}else if(e.key==='Tab'){const f=[inp,cn,ok].filter(x=>!x.disabled),i=f.indexOf(document.activeElement);e.preventDefault();f[(i+(e.shiftKey?-1:1)+f.length)%f.length].focus();}});
bk.addEventListener('pointerdown',e=>{if(e.target===bk)close();});
</script>
</body></html>