FLIP List Reorder Animation
A list whose items glide to their new positions when you shuffle, sort or reverse it.
AI prompt
Clean UI illustration of a list reorder in motion: five rounded rows with coloured left bars and names, two rows shown mid-travel with faint motion trails and a dotted line from their old positions to the new ones, light theme, flat modern style, arrows indicating direction, no gradients. Variants: the list before and after sorting A to Z. Negative: blurred text, heavy shadows, clutter, text errors. Reduced motion: before and after states only.About this pattern
Definition
FLIP stands for First, Last, Invert, Play. Measure where each item is, change the order, measure again, then apply a transform that moves each item back to where it was and animate that transform to zero. The DOM changes once, yet every item visibly travels.
Purpose & UX principles
- First: record each item's position. Last: reorder the list and record again.
- Invert: translate each item by the difference. Play: transition the transform to none.
- Animate only transform so it stays smooth, and keep keys stable so each item is the same element.
Interaction states
- Shuffle, Sort A to Z and Reverse buttons on a list of five items.
Motion specification
- 320ms ease with a small stagger by position.
- Reduced motion: the list reorders instantly.
Responsive behaviour
- Keep durations short (250 to 350ms) for lists people use often.
- Skip the animation for users who prefer reduced motion.
Code
<div class="bx"><div class="ac"><button class="mini" data-a="s" type="button">Shuffle</button><button class="mini" data-a="a" type="button">Sort A to Z</button><button class="mini" data-a="r" type="button">Reverse</button></div><ul class="ls" id="ls"></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}
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}
.ac{display:flex;gap:6px;flex-wrap:wrap}.ls{list-style:none;display:grid;gap:5px}.ls li{display:flex;align-items:center;gap:10px;border:1px solid var(--line);border-radius:10px;background:var(--surface);padding:8px 12px;font-size:13px}.ls li i{width:6px;height:18px;border-radius:3px}
.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}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}const N=[['Mango','#f2a33a'],['Apple','#e5564a'],['Kiwi','#6aa84f'],['Blueberry','#4a6fd1'],['Cherry','#b02a4d']],ls=document.getElementById('ls');let ord=N.slice();const calm=matchMedia('(prefers-reduced-motion:reduce)').matches;
const els={};N.forEach(n=>{const l=document.createElement('li');l.innerHTML='<i style="background:'+n[1]+'"></i>'+n[0];els[n[0]]=l;ls.appendChild(l);});
function flip(fn){const f={};Object.keys(els).forEach(k=>f[k]=els[k].getBoundingClientRect().top);fn();ord.forEach((n,i)=>{ls.appendChild(els[n[0]]);});if(calm)return;ord.forEach((n,i)=>{const e=els[n[0]],d=f[n[0]]-e.getBoundingClientRect().top;e.style.transition='none';e.style.transform='translateY('+d+'px)';requestAnimationFrame(()=>requestAnimationFrame(()=>{e.style.transition='transform .32s cubic-bezier(.2,.7,.2,1) '+(i*20)+'ms';e.style.transform='';}));});}
document.querySelector('.ac').addEventListener('click',e=>{const b=e.target.closest('button');if(!b)return;flip(()=>{if(b.dataset.a==='s'){for(let i=ord.length-1;i>0;i--){const j=Math.floor(Math.random()*(i+1));[ord[i],ord[j]]=[ord[j],ord[i]];}}else if(b.dataset.a==='a')ord.sort((a,c)=>a[0].localeCompare(c[0]));else ord.reverse();});});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>FLIP List Reorder Animation — 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}
.ac{display:flex;gap:6px;flex-wrap:wrap}.ls{list-style:none;display:grid;gap:5px}.ls li{display:flex;align-items:center;gap:10px;border:1px solid var(--line);border-radius:10px;background:var(--surface);padding:8px 12px;font-size:13px}.ls li i{width:6px;height:18px;border-radius:3px}
.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}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
</style></head>
<body><div class="stage">
<div class="bx"><div class="ac"><button class="mini" data-a="s" type="button">Shuffle</button><button class="mini" data-a="a" type="button">Sort A to Z</button><button class="mini" data-a="r" type="button">Reverse</button></div><ul class="ls" id="ls"></ul></div>
</div>
<script>
const N=[['Mango','#f2a33a'],['Apple','#e5564a'],['Kiwi','#6aa84f'],['Blueberry','#4a6fd1'],['Cherry','#b02a4d']],ls=document.getElementById('ls');let ord=N.slice();const calm=matchMedia('(prefers-reduced-motion:reduce)').matches;
const els={};N.forEach(n=>{const l=document.createElement('li');l.innerHTML='<i style="background:'+n[1]+'"></i>'+n[0];els[n[0]]=l;ls.appendChild(l);});
function flip(fn){const f={};Object.keys(els).forEach(k=>f[k]=els[k].getBoundingClientRect().top);fn();ord.forEach((n,i)=>{ls.appendChild(els[n[0]]);});if(calm)return;ord.forEach((n,i)=>{const e=els[n[0]],d=f[n[0]]-e.getBoundingClientRect().top;e.style.transition='none';e.style.transform='translateY('+d+'px)';requestAnimationFrame(()=>requestAnimationFrame(()=>{e.style.transition='transform .32s cubic-bezier(.2,.7,.2,1) '+(i*20)+'ms';e.style.transform='';}));});}
document.querySelector('.ac').addEventListener('click',e=>{const b=e.target.closest('button');if(!b)return;flip(()=>{if(b.dataset.a==='s'){for(let i=ord.length-1;i>0;i--){const j=Math.floor(Math.random()*(i+1));[ord[i],ord[j]]=[ord[j],ord[i]];}}else if(b.dataset.a==='a')ord.sort((a,c)=>a[0].localeCompare(c[0]));else ord.reverse();});});
</script>
</body></html>