Inline Confirm Button
A destructive button that asks for a second press in place, turns red, and resets itself after a few seconds.
AI prompt
Clean UI mockup showing the same button in three states side by side, a neutral outlined Delete project button, the same button turned solid red reading Click again to confirm with a thin white countdown bar shrinking along the bottom edge, and a final grey state reading Project deleted with a small checkmark, light theme, flat modern style, the three buttons the same width. Negative: modal dialogs, heavy shadows, text errors, clutter. Reduced motion: static design.About this pattern
Definition
An inline confirm button avoids a modal for low-stakes destructive actions. The first press changes the label to Confirm and the colour to red; a second press performs the action. If nothing happens for a few seconds, it resets, so the risky state never lingers.
Purpose & UX principles
- First press: change the label and colour, move focus to stay on the button, announce the change.
- Second press: do the action.
- Reset after about 3 seconds, on blur or on Escape.
- Keep the button width stable so the layout does not jump.
Interaction states
- One button with states: idle, confirm, done; a Reset demo button.
Motion specification
- The colour change takes 150ms; a thin bar shows the reset countdown.
- Reduced motion: no countdown bar animation and no transition.
Responsive behaviour
- Use it for reversible or low-impact actions; use a dialog or type-to-confirm for serious ones.
- Announce Are you sure to screen readers with a live region.
Code
<div class="bx"><div class="rw0"><button class="cb" id="cb" type="button" data-s="0"><span id="cl">Delete project</span><i></i></button></div><p class="out" id="out" role="status"></p><button class="mini" id="rs" type="button">Reset demo</button></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}
.rw0{display:grid;place-items:center;padding:20px 0;border:1px solid var(--line);border-radius:12px;background:var(--surface)}.cb{position:relative;overflow:hidden;width:190px;height:42px;border-radius:10px;border:1.5px solid #c9c9c4;background:#fff;font-size:13.5px;font-weight:600;transition:background .15s,color .15s,border-color .15s}.cb i{position:absolute;left:0;bottom:0;height:3px;background:#fff;width:0}.cb[data-s="1"]{background:#d92d20;color:#fff;border-color:#d92d20}.cb[data-s="1"] i{width:100%;animation:cd 3s linear forwards}.cb[data-s="2"]{background:#ececea;color:#6b6b6b;cursor:default;border-color:#ececea}@keyframes cd{to{width:0}}.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){.cb{transition:none}.cb[data-s="1"] i{animation:none;width:0}}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}const cb=document.getElementById('cb'),cl=document.getElementById('cl'),out=document.getElementById('out');let tm=null;
function set(s){cb.dataset.s=s;clearTimeout(tm);cl.textContent=['Delete project','Click again to confirm','\u2713 Project deleted'][s];if(s===1){out.textContent='Are you sure? Press again within 3 seconds to delete.';tm=setTimeout(()=>{set(0);out.textContent='Cancelled: nothing was deleted.';},3000);}else if(s===2)out.textContent='The project was deleted.';else if(!out.textContent.startsWith('Cancelled'))out.textContent='';}
cb.addEventListener('click',()=>{const s=+cb.dataset.s;if(s===0)set(1);else if(s===1)set(2);});cb.addEventListener('blur',()=>{if(cb.dataset.s==='1'){set(0);out.textContent='Cancelled: nothing was deleted.';}});cb.addEventListener('keydown',e=>{if(e.key==='Escape'&&cb.dataset.s==='1'){set(0);out.textContent='Cancelled: nothing was deleted.';}});
document.getElementById('rs').addEventListener('click',()=>{set(0);out.textContent='';});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>Inline Confirm 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}
.rw0{display:grid;place-items:center;padding:20px 0;border:1px solid var(--line);border-radius:12px;background:var(--surface)}.cb{position:relative;overflow:hidden;width:190px;height:42px;border-radius:10px;border:1.5px solid #c9c9c4;background:#fff;font-size:13.5px;font-weight:600;transition:background .15s,color .15s,border-color .15s}.cb i{position:absolute;left:0;bottom:0;height:3px;background:#fff;width:0}.cb[data-s="1"]{background:#d92d20;color:#fff;border-color:#d92d20}.cb[data-s="1"] i{width:100%;animation:cd 3s linear forwards}.cb[data-s="2"]{background:#ececea;color:#6b6b6b;cursor:default;border-color:#ececea}@keyframes cd{to{width:0}}.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){.cb{transition:none}.cb[data-s="1"] i{animation:none;width:0}}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
</style></head>
<body><div class="stage">
<div class="bx"><div class="rw0"><button class="cb" id="cb" type="button" data-s="0"><span id="cl">Delete project</span><i></i></button></div><p class="out" id="out" role="status"></p><button class="mini" id="rs" type="button">Reset demo</button></div>
</div>
<script>
const cb=document.getElementById('cb'),cl=document.getElementById('cl'),out=document.getElementById('out');let tm=null;
function set(s){cb.dataset.s=s;clearTimeout(tm);cl.textContent=['Delete project','Click again to confirm','\u2713 Project deleted'][s];if(s===1){out.textContent='Are you sure? Press again within 3 seconds to delete.';tm=setTimeout(()=>{set(0);out.textContent='Cancelled: nothing was deleted.';},3000);}else if(s===2)out.textContent='The project was deleted.';else if(!out.textContent.startsWith('Cancelled'))out.textContent='';}
cb.addEventListener('click',()=>{const s=+cb.dataset.s;if(s===0)set(1);else if(s===1)set(2);});cb.addEventListener('blur',()=>{if(cb.dataset.s==='1'){set(0);out.textContent='Cancelled: nothing was deleted.';}});cb.addEventListener('keydown',e=>{if(e.key==='Escape'&&cb.dataset.s==='1'){set(0);out.textContent='Cancelled: nothing was deleted.';}});
document.getElementById('rs').addEventListener('click',()=>{set(0);out.textContent='';});set(0);
</script>
</body></html>