Pull to Refresh
Drag a list downward to reveal a refresh indicator, release past the threshold to reload.
AI prompt
Create a 300x260px feed card with a header strip containing a refresh indicator (circular arrow icon plus status text) hidden above the list, a refresh button in the card corner, and a list of four items. Use pointer events on the list with touch-action none: when the pointer moves downward from a press, translate the list by half the drag distance up to a maximum of 90px and rotate the arrow icon proportionally; at 60px or more change the status to "Release to refresh" and flip the arrow. On release past 60px keep the list at 48px, show a spinner with the text "Refreshing…" for 1.2 seconds, then insert a new item "Just now" at the top and spring back to 0 in 280ms cubic-bezier(.2,.7,.2,1). Releasing earlier springs back without refreshing. The refresh button runs the same sequence. Set aria-busy on the list while refreshing. Under prefers-reduced-motion drop rotations and show only text.About this pattern
Definition
A gesture at the top of a list: pulling it down reveals an indicator that grows with the pull, and releasing beyond a threshold starts a refresh.
Purpose & UX principles
- Familiar way to fetch new content on mobile feeds.
- The indicator tells people how far to pull and when releasing will work.
- Always offer a visible Refresh button as well, since the gesture is invisible to many users.
Interaction states
- Idle, pulling (arrow rotates), ready (arrow flips), refreshing (spinner, list locked), done.
Motion specification
- Pull follows the pointer with 50% damping; release springs back in 280ms cubic-bezier(.2,.7,.2,1).
- The refreshing spinner rotates at 700ms per turn.
- Reduced motion: no rotation, text status ("Refreshing…") instead.
Responsive behaviour
- Works with touch and mouse drag; the pull distance is damped so it never exceeds 90px.
- The refresh button is always shown for keyboard and assistive technology.
Code
<div class="card">
<div class="ind" id="ind"><span class="ic" id="ic">↓</span><span id="txt">Pull to refresh</span></div>
<button class="rb" id="rb" type="button">Refresh</button>
<ul class="feed" id="feed"><li>Maya liked your post</li><li>New comment on Studio</li><li>Jon shared a file</li><li>Backup completed</li></ul>
</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}
.card{position:relative;width:min(300px,100%);height:260px;overflow:hidden;background:var(--bg);border:1px solid var(--line);border-radius:14px}
.ind{position:absolute;top:0;left:0;right:0;height:48px;display:flex;align-items:center;justify-content:center;gap:8px;font-size:12px;color:var(--muted)}
.ic{display:inline-block;transition:transform .15s}
.ic.spin{animation:r .7s linear infinite}
@keyframes r{to{transform:rotate(360deg)}}
.feed{position:relative;list-style:none;background:var(--surface);min-height:100%;touch-action:none;cursor:grab;user-select:none;transition:transform .28s cubic-bezier(.2,.7,.2,1);padding-top:34px}
.feed.pull{transition:none}
.feed li{padding:14px 16px;border-top:1px solid var(--line);font-size:13.5px}
.rb{position:absolute;top:6px;right:8px;z-index:3;height:26px;padding:0 10px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font:inherit;font-size:11.5px;cursor:pointer}
.rb:focus-visible{outline:2px solid var(--accent)}
@media (prefers-reduced-motion:reduce){.feed,.ic{transition:none}.ic.spin{animation:none}}const feed=document.getElementById('feed'),txt=document.getElementById('txt'),ic=document.getElementById('ic');
let busy=false,y0=0,d=0,drag=false;
function refresh(){if(busy)return;busy=true;feed.setAttribute('aria-busy','true');feed.classList.remove('pull');feed.style.transform='translateY(48px)';ic.textContent='↻';ic.classList.add('spin');txt.textContent='Refreshing…';
setTimeout(()=>{const li=document.createElement('li');li.textContent='Just now: refreshed';feed.prepend(li);if(feed.children.length>6)feed.lastChild.remove();feed.style.transform='';ic.classList.remove('spin');ic.style.transform='';ic.textContent='↓';txt.textContent='Pull to refresh';feed.removeAttribute('aria-busy');busy=false;},1200);}
feed.addEventListener('pointerdown',e=>{if(busy)return;drag=true;y0=e.clientY;d=0;feed.classList.add('pull');feed.setPointerCapture(e.pointerId);});
feed.addEventListener('pointermove',e=>{if(!drag)return;d=Math.max(0,Math.min(90,(e.clientY-y0)/2));feed.style.transform='translateY('+d+'px)';ic.style.transform='rotate('+(d>=60?180:d*3)+'deg)';txt.textContent=d>=60?'Release to refresh':'Pull to refresh';});
const up=()=>{if(!drag)return;drag=false;feed.classList.remove('pull');if(d>=60)refresh();else{feed.style.transform='';ic.style.transform='';txt.textContent='Pull to refresh';}};
feed.addEventListener('pointerup',up);feed.addEventListener('pointercancel',up);
document.getElementById('rb').addEventListener('click',refresh);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>Pull to Refresh — 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}}
.card{position:relative;width:min(300px,100%);height:260px;overflow:hidden;background:var(--bg);border:1px solid var(--line);border-radius:14px}
.ind{position:absolute;top:0;left:0;right:0;height:48px;display:flex;align-items:center;justify-content:center;gap:8px;font-size:12px;color:var(--muted)}
.ic{display:inline-block;transition:transform .15s}
.ic.spin{animation:r .7s linear infinite}
@keyframes r{to{transform:rotate(360deg)}}
.feed{position:relative;list-style:none;background:var(--surface);min-height:100%;touch-action:none;cursor:grab;user-select:none;transition:transform .28s cubic-bezier(.2,.7,.2,1);padding-top:34px}
.feed.pull{transition:none}
.feed li{padding:14px 16px;border-top:1px solid var(--line);font-size:13.5px}
.rb{position:absolute;top:6px;right:8px;z-index:3;height:26px;padding:0 10px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font:inherit;font-size:11.5px;cursor:pointer}
.rb:focus-visible{outline:2px solid var(--accent)}
@media (prefers-reduced-motion:reduce){.feed,.ic{transition:none}.ic.spin{animation:none}}
</style></head>
<body><div class="stage">
<div class="card">
<div class="ind" id="ind"><span class="ic" id="ic">↓</span><span id="txt">Pull to refresh</span></div>
<button class="rb" id="rb" type="button">Refresh</button>
<ul class="feed" id="feed"><li>Maya liked your post</li><li>New comment on Studio</li><li>Jon shared a file</li><li>Backup completed</li></ul>
</div>
</div>
<script>
const feed=document.getElementById('feed'),txt=document.getElementById('txt'),ic=document.getElementById('ic');
let busy=false,y0=0,d=0,drag=false;
function refresh(){if(busy)return;busy=true;feed.setAttribute('aria-busy','true');feed.classList.remove('pull');feed.style.transform='translateY(48px)';ic.textContent='↻';ic.classList.add('spin');txt.textContent='Refreshing…';
setTimeout(()=>{const li=document.createElement('li');li.textContent='Just now: refreshed';feed.prepend(li);if(feed.children.length>6)feed.lastChild.remove();feed.style.transform='';ic.classList.remove('spin');ic.style.transform='';ic.textContent='↓';txt.textContent='Pull to refresh';feed.removeAttribute('aria-busy');busy=false;},1200);}
feed.addEventListener('pointerdown',e=>{if(busy)return;drag=true;y0=e.clientY;d=0;feed.classList.add('pull');feed.setPointerCapture(e.pointerId);});
feed.addEventListener('pointermove',e=>{if(!drag)return;d=Math.max(0,Math.min(90,(e.clientY-y0)/2));feed.style.transform='translateY('+d+'px)';ic.style.transform='rotate('+(d>=60?180:d*3)+'deg)';txt.textContent=d>=60?'Release to refresh':'Pull to refresh';});
const up=()=>{if(!drag)return;drag=false;feed.classList.remove('pull');if(d>=60)refresh();else{feed.style.transform='';ic.style.transform='';txt.textContent='Pull to refresh';}};
feed.addEventListener('pointerup',up);feed.addEventListener('pointercancel',up);
document.getElementById('rb').addEventListener('click',refresh);
</script>
</body></html>