Edge Swipe Back Gesture
Drag from the left edge to pull the page away and reveal the previous one, with a Back button.
AI prompt
Illustration sequence in three frames of a phone screen stack: frame one a Detail page at rest, frame two the Detail page dragged halfway to the right by a thumb starting at the left edge with the previous Home page peeking in from the left slightly dimmed and offset, frame three the Home page fully revealed, thin arrows and a dashed edge zone along the left side, light theme, flat vector style. Negative: gradients, clutter, text errors, real device logos. Reduced motion: static sequence.About this pattern
Definition
The edge swipe is a navigation gesture: touch near the left edge and drag right, and the current screen follows the finger while the previous screen slides in underneath at a slower pace. If you pass about a third of the width or flick fast, it commits; otherwise it springs back. Every gesture needs a visible button alternative.
Purpose & UX principles
- Start only when the pointer begins within about 24 pixels of the edge, to avoid conflicts with content swipes.
- Move the top page one to one with the finger, the lower page at about 30 percent of the distance, and dim it a little.
- On release, commit if past the threshold or fast, otherwise animate back.
- Always provide a Back button for keyboard and assistive technology users.
Interaction states
- Drag from the left edge of the phone frame, or use the Back button; Open detail goes forward again.
Motion specification
- Release animates over 250ms.
- Reduced motion: it commits or cancels without animation.
Responsive behaviour
- Use touch-action to keep the browser from also scrolling or going back.
- Do not trap people; Escape or the Back button must always work.
Code
<div class="bx"><div class="ph" id="ph"><section class="pg a" id="pa"><h4>Home</h4><p>Your recent items.</p><button class="mini" id="op" type="button">Open detail →</button></section><section class="pg b" id="pb"><header><button class="mini" id="bk" type="button">← Back</button><b>Detail</b></header><p>Swipe from the left edge to go back.</p><i class="ed"></i></section></div><p class="out" id="out" role="status"></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}
.ph{user-select:none;-webkit-user-select:none;position:relative;height:150px;border-radius:14px;overflow:hidden;border:1px solid var(--line);background:#e9e9e6;touch-action:pan-y}.pg{position:absolute;inset:0;padding:12px;background:#fff;font-size:12.5px}.pg h4{margin:0 0 4px;font-size:15px}.pg p{margin:0 0 8px;color:var(--muted)}.pg.a{z-index:1}.pg.b{z-index:2;box-shadow:-6px 0 14px rgba(0,0,0,.15);touch-action:none}.pg.b header{display:flex;gap:8px;align-items:center;margin-bottom:8px}.ed{position:absolute;left:0;top:0;bottom:0;width:24px;background:linear-gradient(90deg,rgba(47,107,255,.12),transparent);pointer-events:none}.dm{position:absolute;inset:0;background:#000;opacity:0;pointer-events:none;z-index:1.5}.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}.out{font-size:12px;color:var(--muted);min-height:16px;margin:0}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}const ph=document.getElementById('ph'),A=document.getElementById('pa'),B=document.getElementById('pb'),out=document.getElementById('out'),calm=matchMedia('(prefers-reduced-motion:reduce)').matches;let x=0,drag=false,showB=true,sx=0,st=0,raf=0;
function W(){return ph.clientWidth;}
function draw(px){B.style.transform='translateX('+px+'px)';const k=px/W();A.style.transform='translateX('+(-30*(1-k)).toString()+'%)';A.style.filter='brightness('+(0.88+.12*k)+')';}
function anim(to,done){cancelAnimationFrame(raf);if(calm){x=to;draw(x);done&&done();return;}const from=x,t0=performance.now();(function f(n){const k=Math.min(1,(n-t0)/250),e=1-Math.pow(1-k,3);x=from+(to-from)*e;draw(x);if(k<1)raf=requestAnimationFrame(f);else done&&done();})(t0);}
function goBack(){anim(W(),()=>{showB=false;B.style.visibility='hidden';out.textContent='Back on Home.';});}
function open(){B.style.visibility='visible';showB=true;x=W();draw(x);anim(0,()=>{out.textContent='Detail open.';});}
ph.addEventListener('pointerdown',e=>{if(!showB)return;const r=ph.getBoundingClientRect();if(e.clientX-r.left>24)return;drag=true;sx=e.clientX;st=performance.now();ph.setPointerCapture(e.pointerId);cancelAnimationFrame(raf);});
ph.addEventListener('pointermove',e=>{if(!drag)return;x=Math.max(0,e.clientX-sx);draw(x);out.textContent='Dragging\u2026 '+Math.round(x/W()*100)+'%';});
['pointerup','pointercancel'].forEach(t=>ph.addEventListener(t,e=>{if(!drag)return;drag=false;const v=x/Math.max(1,performance.now()-st);if(x>W()*.33||v>.6)goBack();else{anim(0,()=>{out.textContent='Cancelled: stayed on Detail.';});}}));
document.getElementById('bk').addEventListener('click',goBack);document.getElementById('op').addEventListener('click',open);
document.addEventListener('keydown',e=>{if(e.key==='Escape'&&showB)goBack();});draw(0);out.textContent='Drag from the left edge, or press Back.';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>Edge Swipe Back Gesture — 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}
.ph{user-select:none;-webkit-user-select:none;position:relative;height:150px;border-radius:14px;overflow:hidden;border:1px solid var(--line);background:#e9e9e6;touch-action:pan-y}.pg{position:absolute;inset:0;padding:12px;background:#fff;font-size:12.5px}.pg h4{margin:0 0 4px;font-size:15px}.pg p{margin:0 0 8px;color:var(--muted)}.pg.a{z-index:1}.pg.b{z-index:2;box-shadow:-6px 0 14px rgba(0,0,0,.15);touch-action:none}.pg.b header{display:flex;gap:8px;align-items:center;margin-bottom:8px}.ed{position:absolute;left:0;top:0;bottom:0;width:24px;background:linear-gradient(90deg,rgba(47,107,255,.12),transparent);pointer-events:none}.dm{position:absolute;inset:0;background:#000;opacity:0;pointer-events:none;z-index:1.5}.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}.out{font-size:12px;color:var(--muted);min-height:16px;margin:0}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
</style></head>
<body><div class="stage">
<div class="bx"><div class="ph" id="ph"><section class="pg a" id="pa"><h4>Home</h4><p>Your recent items.</p><button class="mini" id="op" type="button">Open detail →</button></section><section class="pg b" id="pb"><header><button class="mini" id="bk" type="button">← Back</button><b>Detail</b></header><p>Swipe from the left edge to go back.</p><i class="ed"></i></section></div><p class="out" id="out" role="status"></p></div>
</div>
<script>
const ph=document.getElementById('ph'),A=document.getElementById('pa'),B=document.getElementById('pb'),out=document.getElementById('out'),calm=matchMedia('(prefers-reduced-motion:reduce)').matches;let x=0,drag=false,showB=true,sx=0,st=0,raf=0;
function W(){return ph.clientWidth;}
function draw(px){B.style.transform='translateX('+px+'px)';const k=px/W();A.style.transform='translateX('+(-30*(1-k)).toString()+'%)';A.style.filter='brightness('+(0.88+.12*k)+')';}
function anim(to,done){cancelAnimationFrame(raf);if(calm){x=to;draw(x);done&&done();return;}const from=x,t0=performance.now();(function f(n){const k=Math.min(1,(n-t0)/250),e=1-Math.pow(1-k,3);x=from+(to-from)*e;draw(x);if(k<1)raf=requestAnimationFrame(f);else done&&done();})(t0);}
function goBack(){anim(W(),()=>{showB=false;B.style.visibility='hidden';out.textContent='Back on Home.';});}
function open(){B.style.visibility='visible';showB=true;x=W();draw(x);anim(0,()=>{out.textContent='Detail open.';});}
ph.addEventListener('pointerdown',e=>{if(!showB)return;const r=ph.getBoundingClientRect();if(e.clientX-r.left>24)return;drag=true;sx=e.clientX;st=performance.now();ph.setPointerCapture(e.pointerId);cancelAnimationFrame(raf);});
ph.addEventListener('pointermove',e=>{if(!drag)return;x=Math.max(0,e.clientX-sx);draw(x);out.textContent='Dragging\u2026 '+Math.round(x/W()*100)+'%';});
['pointerup','pointercancel'].forEach(t=>ph.addEventListener(t,e=>{if(!drag)return;drag=false;const v=x/Math.max(1,performance.now()-st);if(x>W()*.33||v>.6)goBack();else{anim(0,()=>{out.textContent='Cancelled: stayed on Detail.';});}}));
document.getElementById('bk').addEventListener('click',goBack);document.getElementById('op').addEventListener('click',open);
document.addEventListener('keydown',e=>{if(e.key==='Escape'&&showB)goBack();});draw(0);out.textContent='Drag from the left edge, or press Back.';
</script>
</body></html>