# Pull to Refresh

Pulling down on a print log adds a newly arrived record.

## Try it

Pull down from the top of the list and release when the indicator changes, or use the refresh button.

## Interaction details

The trigger requires 82px of pointer movement. An early release or cancellation returns the list to rest. While refreshing, ignore repeat input. Each refresh adds one of three sample records. Reduced motion uses a status message in place of rotation.

## Platform controls

- iOS · Pull down from the arrow at the top and release. You can also tap the refresh button.
- Android · Pull down from the arrow and release when the refresh message appears.
- PC · Drag the top of the list downward, or focus the refresh button and press Enter.

## Where to use it

Refreshing feeds or work queues at the reader's request.

## Implementation prompt

> Refresh once after a deliberate pull, then add the new record at the top.

## Sources and credits

[Android Developers · Pull to refresh](<https://developer.android.com/develop/ui/compose/components/pull-to-refresh>)

## Standalone HTML

Save the code below as an HTML file and open it in your browser. The example works offline.

```html
<!doctype html>
<html lang="en"><head><script>if(new URLSearchParams(location.search).get('reduce')==='1')document.documentElement.classList.add('motion-reduced');</script><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Pull to Refresh · Motion Lab</title>
<style>
*{box-sizing:border-box}html{color-scheme:light}body{margin:0;font:15px/1.5 system-ui,-apple-system,'Malgun Gothic',sans-serif;word-break:keep-all}main{margin:auto}button{font:inherit;color:inherit;cursor:pointer}button:focus-visible,[tabindex]:focus-visible{outline:3px solid #005bc6;outline-offset:2px}button:disabled{cursor:default}h1,h2,p{margin:0}h1{font-size:clamp(26px,5vw,42px);font-weight:750;letter-spacing:-.075em;line-height:1.2}h2{font-size:18px;letter-spacing:-.04em}.mono{font:600 11px/1.4 ui-monospace,Consolas,monospace;letter-spacing:.055em}.sr{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}button{touch-action:manipulation}html.motion-reduced *,html.motion-reduced *::before,html.motion-reduced *::after{animation-duration:.01ms!important;animation-iteration-count:1!important;transition-duration:.01ms!important;scroll-behavior:auto!important}@media(prefers-reduced-motion:reduce){*,*::before,*::after{animation-duration:.01ms!important;animation-iteration-count:1!important;transition-duration:.01ms!important;scroll-behavior:auto!important}}

body{background:#dae4d9;color:#132d25}main{width:min(100%,660px);padding:clamp(15px,4vw,40px)}.ledger{background:#f3f3dd;border-block:2px solid #183e31;padding:clamp(15px,4vw,32px);box-shadow:0 12px 35px #153a2517}.head,.foot,.row{display:flex;align-items:center;justify-content:space-between;gap:12px}.head{align-items:end}.head h1{margin-top:5px}.seal{display:grid;place-items:center;border:2px double #27503b;color:#27503b;border-radius:50%;width:64px;height:64px;text-align:center;line-height:1.08;transform:rotate(-10deg);font:italic 700 18px/1 Georgia,serif}.pull{margin-top:18px;height:50px;touch-action:none;cursor:grab;user-select:none;display:flex;align-items:center;justify-content:center;gap:8px;background:#d7e2c5;border-block:1px dashed #708771;color:#214833}.pull:active{cursor:grabbing}.dial{font-size:24px;line-height:1}.well{overflow:hidden}.rows{list-style:none;padding:0;margin:0;transform:translateY(var(--pull,0px));transition:transform .28s cubic-bezier(.19,.8,.24,1)}.dragging .rows{transition:none}.row{position:relative;min-height:58px;justify-content:flex-start;padding:8px 0;border-bottom:1px solid #abb59e}.row time{margin-left:auto;font-size:12px}.thumb{height:36px;width:34px;flex:none;background:radial-gradient(ellipse at 47% 45%,var(--tone) 0 34%,#f9e2a4 35% 41%,transparent 42%),repeating-linear-gradient(33deg,#244c39 0 2px,#96ab79 2px 5px);border:1px solid #12352e}.row strong{display:block;font-size:15px}.row small{color:#435547;font-size:11px}.foot{margin-top:13px}.foot p{font-size:12px;color:#344e3d}.foot button{border:0;background:#244532;color:white;min-height:44px;padding:6px 16px;font-weight:700}.foot button:disabled{background:#4c5e50}.busy .dial{animation:spin .72s linear infinite}.row.new{animation:arrival .45s ease-out}@keyframes spin{to{transform:rotate(1turn)}}@keyframes arrival{from{opacity:.15;transform:translateY(-18px)}to{opacity:1;transform:none}}@media(max-width:370px){.seal{width:48px;height:48px;font-size:15px}.row{gap:8px}.foot button{padding-inline:10px}}

</style></head><body>

<main><section class="ledger" aria-labelledby="title"><header class="head"><div><span class="mono">Pressroom · Receiving log</span><h1 id="title">Today’s proofs</h1></div><span class="seal" aria-hidden="true">Proof<br>Desk</span></header>
<div class="pull" id="pull"><span class="dial" aria-hidden="true">↓</span><span id="hint">Pull down for new entries</span></div>
<div class="well"><ul class="rows" id="rows" aria-label="Recent arrivals"></ul></div><footer class="foot"><p id="status" role="status">3 recent arrivals</p><button id="refresh" type="button">Refresh</button></footer></section></main>

<script>

const rows=document.getElementById('rows'),pull=document.getElementById('pull'),hint=document.getElementById('hint'),status=document.getElementById('status'),refresh=document.getElementById('refresh'),ledger=document.querySelector('.ledger');
const records=[['Summer Binding','Cover proof','09:12','#ab5030'],['Wave Intervals','Text proof','09:45','#356258'],['Park Type','Spot color check','10:20','#2c4f48'],['Green Print Studio','Riso poster','10:32','#d35c37'],['Window Specimen','Spot color proof','10:47','#45699d'],['Walking Coordinates','Fold proof','11:08','#8f4151']];
let total=3,gesture=null,busy=false;
function display(fresh){rows.replaceChildren(...records.slice(0,total).reverse().slice(0,3).map(([name,detail,time,tone],i)=>{const li=document.createElement('li');li.className='row'+(fresh&&i===0?' new':'');li.innerHTML='<i aria-hidden="true" class="thumb"></i><div><strong></strong><small></small></div><time class="mono"></time>';li.style.setProperty('--tone',tone);li.querySelector('strong').textContent=name;li.querySelector('small').textContent=detail;li.querySelector('time').textContent=time;return li;}));}
function rest(){ledger.classList.remove('dragging');rows.style.removeProperty('--pull');pull.querySelector('.dial').style.removeProperty('transform');hint.textContent='Pull down for new entries';}
function load(){if(busy)return;rest();gesture=null;busy=true;ledger.classList.add('busy');refresh.disabled=true;rows.setAttribute('aria-busy','true');pull.querySelector('.dial').textContent='↻';hint.textContent='Checking records';status.textContent='Checking the pressroom log.';
setTimeout(()=>{const fresh=total<records.length;if(fresh)total++;display(fresh);busy=false;refresh.disabled=false;ledger.classList.remove('busy');rows.setAttribute('aria-busy','false');rest();pull.querySelector('.dial').textContent='↓';status.textContent=fresh?records[total-1][0]+' received · Showing latest three':'All records are up to date.';},450);}
pull.addEventListener('pointerdown',e=>{if(!e.isPrimary||e.button!==0||busy)return;gesture={id:e.pointerId,start:e.clientY,dy:0};pull.setPointerCapture(e.pointerId);ledger.classList.add('dragging');});
pull.addEventListener('pointermove',e=>{if(!gesture||e.pointerId!==gesture.id)return;gesture.dy=Math.max(0,e.clientY-gesture.start);rows.style.setProperty('--pull',Math.min(44,gesture.dy*.45)+'px');pull.querySelector('.dial').style.transform='rotate('+Math.min(180,gesture.dy*2)+'deg)';hint.textContent=gesture.dy>=82?'Release to refresh':'Pull a little further';});
function finish(e){if(!gesture||e.pointerId!==gesture.id)return;const commit=e.type==='pointerup'&&gesture.dy>=82;gesture=null;rest();if(commit)load();}
['pointerup','pointercancel','lostpointercapture'].forEach(type=>pull.addEventListener(type,finish));
document.addEventListener('keydown',e=>{if(e.key==='Escape'&&gesture){gesture=null;rest();}});refresh.addEventListener('click',load);display(false);

</script></body></html>
```
