Slide to Confirm
A confirmation control where a thumb must be dragged all the way across to proceed.
AI prompt
Create a slide-to-confirm control 280px wide and 52px tall with a pill-shaped track, a label "Slide to pay" centered, a progress fill that grows with the thumb and a 44px circular thumb button with an arrow. Use pointer events on the thumb with touch-action none: move it horizontally within the track, set the fill width and the label opacity to 1 minus progress. On release at 90% or more, move it to the end, replace the arrow with a check mark, change the label to "Paid" and lock the control; otherwise return the thumb with a 260ms cubic-bezier(.2,.7,.2,1) transition. Give the thumb role slider with aria-valuemin 0, aria-valuemax 100 and aria-valuenow updated, aria-label "Slide to pay"; ArrowRight and ArrowLeft change the value by 25 and reaching 100 confirms. Add a small Reset link after confirming. Under prefers-reduced-motion remove transitions.About this pattern
Definition
A track with a draggable thumb. The action only happens when the thumb is dragged to the end, which prevents accidental taps on important actions.
Purpose & UX principles
- Adds deliberate friction to actions that are costly to trigger by mistake, such as payments or unlocking.
- A label on the track explains the action; the track text fades as the thumb moves.
- Keyboard and assistive technology users press ArrowRight on the thumb or use Enter to confirm in steps.
Interaction states
- Idle, dragging, confirmed (check mark, locked), released early (springs back), focus-visible.
Motion specification
- The thumb follows the pointer with no delay; release back is 260ms cubic-bezier(.2,.7,.2,1).
- The fill behind the thumb grows with it; the label opacity follows 1 - progress.
- Reduced motion: no spring, thumb jumps back instantly.
Responsive behaviour
- Track width follows its container with a 52px tall thumb for easy touch.
- Distance is measured relative to the track, so it works at any width.
Code
<div class="box">
<div class="track" id="trk"><div class="fill" id="fill"></div><span class="lbl" id="lbl">Slide to pay</span>
<div class="thumb" id="th" role="slider" tabindex="0" aria-label="Slide to pay" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0">→</div></div>
<button class="reset" id="rs" type="button" hidden>Reset</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}
.box{width:min(280px,100%);display:grid;gap:10px;justify-items:center}
.track{position:relative;width:100%;height:52px;border-radius:26px;background:var(--surface);border:1px solid var(--line);overflow:hidden}
.fill{position:absolute;inset:0 auto 0 0;width:0;background:#e4e4e0}
.lbl{position:absolute;inset:0;display:grid;place-items:center;font-size:13.5px;font-weight:500;pointer-events:none;padding-left:30px}
.thumb{position:absolute;left:4px;top:3px;width:44px;height:44px;border-radius:50%;background:var(--accent);color:var(--accent-ink);display:grid;place-items:center;font-size:18px;cursor:grab;touch-action:none;user-select:none}
.thumb.back{transition:left .26s cubic-bezier(.2,.7,.2,1)}
.fill.back{transition:width .26s cubic-bezier(.2,.7,.2,1)}
.thumb:focus-visible{outline:2px solid var(--accent);outline-offset:3px}
.done .thumb{cursor:default}
.reset{background:none;border:0;font:inherit;font-size:12px;color:var(--muted);text-decoration:underline;cursor:pointer}
@media (prefers-reduced-motion:reduce){.thumb.back,.fill.back{transition:none}}const trk=document.getElementById('trk'),th=document.getElementById('th'),fill=document.getElementById('fill'),lbl=document.getElementById('lbl'),rs=document.getElementById('rs');
const max=()=>trk.clientWidth-th.offsetWidth-8;let p=0,drag=false,sx=0,s0=0,locked=false;
function view(v,anim){th.classList.toggle('back',!!anim);fill.classList.toggle('back',!!anim);p=Math.max(0,Math.min(1,v));th.style.left=(4+p*max())+'px';fill.style.width=(4+p*max()+22)+'px';lbl.style.opacity=1-p;th.setAttribute('aria-valuenow',Math.round(p*100));}
function confirm(){locked=true;view(1,true);th.textContent='✓';lbl.style.opacity=1;lbl.textContent='Paid';trk.classList.add('done');rs.hidden=false;}
th.addEventListener('pointerdown',e=>{if(locked)return;drag=true;sx=e.clientX;s0=p;th.classList.remove('back');fill.classList.remove('back');th.setPointerCapture(e.pointerId);});
th.addEventListener('pointermove',e=>{if(drag)view(s0+(e.clientX-sx)/max());});
const up=()=>{if(!drag)return;drag=false;if(p>=.9)confirm();else view(0,true);};
th.addEventListener('pointerup',up);th.addEventListener('pointercancel',up);
th.addEventListener('keydown',e=>{if(locked)return;if(e.key==='ArrowRight'){e.preventDefault();view(p+.25,true);if(p>=1)confirm();}if(e.key==='ArrowLeft'){e.preventDefault();view(p-.25,true);}});
rs.addEventListener('click',()=>{locked=false;th.textContent='→';lbl.textContent='Slide to pay';trk.classList.remove('done');rs.hidden=true;view(0,true);});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>Slide to Confirm — 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}}
.box{width:min(280px,100%);display:grid;gap:10px;justify-items:center}
.track{position:relative;width:100%;height:52px;border-radius:26px;background:var(--surface);border:1px solid var(--line);overflow:hidden}
.fill{position:absolute;inset:0 auto 0 0;width:0;background:#e4e4e0}
.lbl{position:absolute;inset:0;display:grid;place-items:center;font-size:13.5px;font-weight:500;pointer-events:none;padding-left:30px}
.thumb{position:absolute;left:4px;top:3px;width:44px;height:44px;border-radius:50%;background:var(--accent);color:var(--accent-ink);display:grid;place-items:center;font-size:18px;cursor:grab;touch-action:none;user-select:none}
.thumb.back{transition:left .26s cubic-bezier(.2,.7,.2,1)}
.fill.back{transition:width .26s cubic-bezier(.2,.7,.2,1)}
.thumb:focus-visible{outline:2px solid var(--accent);outline-offset:3px}
.done .thumb{cursor:default}
.reset{background:none;border:0;font:inherit;font-size:12px;color:var(--muted);text-decoration:underline;cursor:pointer}
@media (prefers-reduced-motion:reduce){.thumb.back,.fill.back{transition:none}}
</style></head>
<body><div class="stage">
<div class="box">
<div class="track" id="trk"><div class="fill" id="fill"></div><span class="lbl" id="lbl">Slide to pay</span>
<div class="thumb" id="th" role="slider" tabindex="0" aria-label="Slide to pay" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0">→</div></div>
<button class="reset" id="rs" type="button" hidden>Reset</button>
</div>
</div>
<script>
const trk=document.getElementById('trk'),th=document.getElementById('th'),fill=document.getElementById('fill'),lbl=document.getElementById('lbl'),rs=document.getElementById('rs');
const max=()=>trk.clientWidth-th.offsetWidth-8;let p=0,drag=false,sx=0,s0=0,locked=false;
function view(v,anim){th.classList.toggle('back',!!anim);fill.classList.toggle('back',!!anim);p=Math.max(0,Math.min(1,v));th.style.left=(4+p*max())+'px';fill.style.width=(4+p*max()+22)+'px';lbl.style.opacity=1-p;th.setAttribute('aria-valuenow',Math.round(p*100));}
function confirm(){locked=true;view(1,true);th.textContent='✓';lbl.style.opacity=1;lbl.textContent='Paid';trk.classList.add('done');rs.hidden=false;}
th.addEventListener('pointerdown',e=>{if(locked)return;drag=true;sx=e.clientX;s0=p;th.classList.remove('back');fill.classList.remove('back');th.setPointerCapture(e.pointerId);});
th.addEventListener('pointermove',e=>{if(drag)view(s0+(e.clientX-sx)/max());});
const up=()=>{if(!drag)return;drag=false;if(p>=.9)confirm();else view(0,true);};
th.addEventListener('pointerup',up);th.addEventListener('pointercancel',up);
th.addEventListener('keydown',e=>{if(locked)return;if(e.key==='ArrowRight'){e.preventDefault();view(p+.25,true);if(p>=1)confirm();}if(e.key==='ArrowLeft'){e.preventDefault();view(p-.25,true);}});
rs.addEventListener('click',()=>{locked=false;th.textContent='→';lbl.textContent='Slide to pay';trk.classList.remove('done');rs.hidden=true;view(0,true);});
</script>
</body></html>