Swipe Decision Cards
Drag the top card left or right; stamps fade in, and releasing past the threshold flies it away. Buttons do the same.
AI prompt
Build a swipe decision card stack with three cards. Pointer-drag the top card horizontally: it follows the pointer with rotation proportional to distance (max 12 degrees), a green "KEEP" stamp fades in when dragging right and a red "SKIP" stamp when dragging left. Releasing beyond 30 percent of the card width flies the card off screen in 250 milliseconds and reveals the next card, which scales from 0.95 to 1; releasing earlier springs the card back. Provide Skip and Keep buttons and ArrowLeft and ArrowRight keys as alternatives, a counter "1 of 3", an empty state with "Start over". Announce decisions via aria-live. touch-action pan-y, prefers-reduced-motion fallback. Plain HTML, CSS and JavaScript.About this pattern
Definition
Swipe decision cards present one item at a time. Dragging the top card sideways signals a choice, with visual stamps showing what will happen before the card is released.
Purpose & UX principles
- Good for fast, low-stakes decisions: matching, triage, sorting.
- Always provide buttons as an alternative for keyboard, assistive tech and people who cannot drag.
- Give clear feedback during the drag (rotation, stamp, colour) and an easy undo for mistakes.
Interaction states
- Idle, dragging (rotation and stamp follow), past threshold (committed), snapping back, empty deck.
Motion specification
- Card rotates up to 12 degrees with drag distance; commit flies out in 250ms; snap-back springs over 220ms; the next card scales from 0.95 to 1.
- Reduced motion: no rotation or fly-out; the card is simply replaced.
Responsive behaviour
- Cards fill the width up to 280px; the swipe threshold scales with card width (about 30%).
- Buttons stay below the stack at 44px tall.
Code
<div class="bx"><div class="deck" id="deck" tabindex="0" aria-label="Card deck, use arrow keys to decide"></div><div class="btn"><button id="no" type="button" aria-label="Skip">✕ Skip</button><button id="yes" type="button" aria-label="Keep">♥ Keep</button></div><p class="out" id="out" aria-live="polite"></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}
.bx{width:min(260px,100%);display:grid;gap:10px;justify-items:center}
.deck{position:relative;width:100%;height:150px;outline:none}.deck:focus-visible{outline:2px solid var(--accent);outline-offset:4px;border-radius:14px}
.cd{position:absolute;inset:0;border-radius:14px;background:var(--surface);border:1px solid var(--line);box-shadow:0 6px 18px rgba(0,0,0,.08);display:grid;place-content:center;justify-items:center;gap:4px;touch-action:pan-y;user-select:none;cursor:grab;will-change:transform}
.cd b{font-size:17px}.cd span{font-size:12px;color:var(--muted)}
.cd .em{font-size:30px}
.cd.back{transform:scale(.95) translateY(8px);cursor:default;transition:transform .2s}
.st{position:absolute;top:12px;padding:2px 10px;border:2px solid;border-radius:6px;font-size:13px;font-weight:800;letter-spacing:.08em;opacity:0}
.st.k{left:12px;color:#1a8f4a;transform:rotate(-8deg)}.st.s{right:12px;color:var(--danger);transform:rotate(8deg)}
.btn{display:flex;gap:8px}.btn button{height:36px;padding:0 20px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:13px;font-weight:600;cursor:pointer}
.out{font-size:12px;color:var(--muted);min-height:16px}
button:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
@media (prefers-reduced-motion:reduce){.cd.back{transition:none}}const D=[['🌋','Volcano trek','Iceland · 4 days'],['🏖️','Beach week','Portugal · 7 days'],['🏔️','Alpine hike','Switzerland · 5 days']],deck=document.getElementById('deck'),out=document.getElementById('out'),no=document.getElementById('no'),yes=document.getElementById('yes');
const reduce=matchMedia('(prefers-reduced-motion: reduce)').matches;let i=0,busy=false;
function render(){deck.innerHTML='';if(i>=D.length){deck.innerHTML='<div class="cd" style="cursor:default"><b>All done</b><button id="rs" type="button" style="margin-top:6px;height:30px;padding:0 16px;border-radius:99px;border:1px solid var(--line);background:var(--surface);cursor:pointer">Start over</button></div>';deck.querySelector('#rs').addEventListener('click',()=>{i=0;out.textContent='';render();});no.disabled=yes.disabled=true;return;}
no.disabled=yes.disabled=false;if(i+1<D.length)deck.append(card(i+1,true));deck.append(card(i,false));}
function card(k,back){const c=document.createElement('div');c.className='cd'+(back?' back':'');c.innerHTML='<i class="st k">KEEP</i><i class="st s">SKIP</i><span class="em">'+D[k][0]+'</span><b>'+D[k][1]+'</b><span>'+D[k][2]+' · '+(k+1)+' of '+D.length+'</span>';if(!back)drag(c);return c;}
function decide(c,dir){if(busy)return;busy=true;out.textContent=(dir>0?'Kept ':'Skipped ')+D[i][1];c.style.transition=reduce?'none':'transform .25s ease-in,opacity .25s';c.style.transform=reduce?'none':'translateX('+(dir*400)+'px) rotate('+(dir*18)+'deg)';c.style.opacity=0;setTimeout(()=>{i++;busy=false;render();},reduce?0:250);}
function drag(c){let sx=0,dx=0,on=false;const k=c.querySelector('.k'),s=c.querySelector('.s');
c.addEventListener('pointerdown',e=>{if(busy)return;on=true;sx=e.clientX;c.setPointerCapture(e.pointerId);c.style.transition='none';});
c.addEventListener('pointermove',e=>{if(!on)return;dx=e.clientX-sx;if(!reduce)c.style.transform='translateX('+dx+'px) rotate('+Math.max(-12,Math.min(12,dx/12))+'deg)';k.style.opacity=Math.max(0,Math.min(1,dx/80));s.style.opacity=Math.max(0,Math.min(1,-dx/80));});
const end=()=>{if(!on)return;on=false;if(Math.abs(dx)>c.offsetWidth*.3)decide(c,dx>0?1:-1);else{c.style.transition=reduce?'none':'transform .22s cubic-bezier(.3,1.4,.5,1)';c.style.transform='none';k.style.opacity=s.style.opacity=0;}dx=0;};c.addEventListener('pointerup',end);c.addEventListener('pointercancel',end);}
function topCard(){return deck.querySelector('.cd:last-child');}
no.addEventListener('click',()=>{if(i<D.length)decide(topCard(),-1);});yes.addEventListener('click',()=>{if(i<D.length)decide(topCard(),1);});
deck.addEventListener('keydown',e=>{if(i>=D.length)return;if(e.key==='ArrowLeft'){e.preventDefault();decide(topCard(),-1);}else if(e.key==='ArrowRight'){e.preventDefault();decide(topCard(),1);}});render();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>Swipe Decision Cards — 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{width:min(260px,100%);display:grid;gap:10px;justify-items:center}
.deck{position:relative;width:100%;height:150px;outline:none}.deck:focus-visible{outline:2px solid var(--accent);outline-offset:4px;border-radius:14px}
.cd{position:absolute;inset:0;border-radius:14px;background:var(--surface);border:1px solid var(--line);box-shadow:0 6px 18px rgba(0,0,0,.08);display:grid;place-content:center;justify-items:center;gap:4px;touch-action:pan-y;user-select:none;cursor:grab;will-change:transform}
.cd b{font-size:17px}.cd span{font-size:12px;color:var(--muted)}
.cd .em{font-size:30px}
.cd.back{transform:scale(.95) translateY(8px);cursor:default;transition:transform .2s}
.st{position:absolute;top:12px;padding:2px 10px;border:2px solid;border-radius:6px;font-size:13px;font-weight:800;letter-spacing:.08em;opacity:0}
.st.k{left:12px;color:#1a8f4a;transform:rotate(-8deg)}.st.s{right:12px;color:var(--danger);transform:rotate(8deg)}
.btn{display:flex;gap:8px}.btn button{height:36px;padding:0 20px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:13px;font-weight:600;cursor:pointer}
.out{font-size:12px;color:var(--muted);min-height:16px}
button:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
@media (prefers-reduced-motion:reduce){.cd.back{transition:none}}
</style></head>
<body><div class="stage">
<div class="bx"><div class="deck" id="deck" tabindex="0" aria-label="Card deck, use arrow keys to decide"></div><div class="btn"><button id="no" type="button" aria-label="Skip">✕ Skip</button><button id="yes" type="button" aria-label="Keep">♥ Keep</button></div><p class="out" id="out" aria-live="polite"></p></div>
</div>
<script>
const D=[['🌋','Volcano trek','Iceland · 4 days'],['🏖️','Beach week','Portugal · 7 days'],['🏔️','Alpine hike','Switzerland · 5 days']],deck=document.getElementById('deck'),out=document.getElementById('out'),no=document.getElementById('no'),yes=document.getElementById('yes');
const reduce=matchMedia('(prefers-reduced-motion: reduce)').matches;let i=0,busy=false;
function render(){deck.innerHTML='';if(i>=D.length){deck.innerHTML='<div class="cd" style="cursor:default"><b>All done</b><button id="rs" type="button" style="margin-top:6px;height:30px;padding:0 16px;border-radius:99px;border:1px solid var(--line);background:var(--surface);cursor:pointer">Start over</button></div>';deck.querySelector('#rs').addEventListener('click',()=>{i=0;out.textContent='';render();});no.disabled=yes.disabled=true;return;}
no.disabled=yes.disabled=false;if(i+1<D.length)deck.append(card(i+1,true));deck.append(card(i,false));}
function card(k,back){const c=document.createElement('div');c.className='cd'+(back?' back':'');c.innerHTML='<i class="st k">KEEP</i><i class="st s">SKIP</i><span class="em">'+D[k][0]+'</span><b>'+D[k][1]+'</b><span>'+D[k][2]+' · '+(k+1)+' of '+D.length+'</span>';if(!back)drag(c);return c;}
function decide(c,dir){if(busy)return;busy=true;out.textContent=(dir>0?'Kept ':'Skipped ')+D[i][1];c.style.transition=reduce?'none':'transform .25s ease-in,opacity .25s';c.style.transform=reduce?'none':'translateX('+(dir*400)+'px) rotate('+(dir*18)+'deg)';c.style.opacity=0;setTimeout(()=>{i++;busy=false;render();},reduce?0:250);}
function drag(c){let sx=0,dx=0,on=false;const k=c.querySelector('.k'),s=c.querySelector('.s');
c.addEventListener('pointerdown',e=>{if(busy)return;on=true;sx=e.clientX;c.setPointerCapture(e.pointerId);c.style.transition='none';});
c.addEventListener('pointermove',e=>{if(!on)return;dx=e.clientX-sx;if(!reduce)c.style.transform='translateX('+dx+'px) rotate('+Math.max(-12,Math.min(12,dx/12))+'deg)';k.style.opacity=Math.max(0,Math.min(1,dx/80));s.style.opacity=Math.max(0,Math.min(1,-dx/80));});
const end=()=>{if(!on)return;on=false;if(Math.abs(dx)>c.offsetWidth*.3)decide(c,dx>0?1:-1);else{c.style.transition=reduce?'none':'transform .22s cubic-bezier(.3,1.4,.5,1)';c.style.transform='none';k.style.opacity=s.style.opacity=0;}dx=0;};c.addEventListener('pointerup',end);c.addEventListener('pointercancel',end);}
function topCard(){return deck.querySelector('.cd:last-child');}
no.addEventListener('click',()=>{if(i<D.length)decide(topCard(),-1);});yes.addEventListener('click',()=>{if(i<D.length)decide(topCard(),1);});
deck.addEventListener('keydown',e=>{if(i>=D.length)return;if(e.key==='ArrowLeft'){e.preventDefault();decide(topCard(),-1);}else if(e.key==='ArrowRight'){e.preventDefault();decide(topCard(),1);}});render();
</script>
</body></html>