# Trello · Reorder cards or move them between lists

Drag a card up or down its current list to change the order of work. Dropping it in another list moves it there, useful when a task goes from a backlog into progress.

[Official source](https://support.atlassian.com/trello/docs/moving-cards-or-lists/)

## Related motion · Reorder List

# Reorder List

Moving a print job changes its position in the production queue.

## Try it

Drag a job by its handle, or use the up and down controls beside it.

## Interaction details

The dragged row follows the pointer while adjacent rows make space. Dropping commits the new order. Escape or cancellation restores the starting order. Disable moves beyond the list boundaries.

## Platform controls

- iOS · Drag a row by its left handle to a new position, or tap its up and down buttons.
- Android · Drag a row by its left handle to a new position, or tap its up and down buttons.
- PC · Drag a handle to reorder. Alternatively, focus a row's up or down button and press Enter.

## Where to use it

Playlists, work queues, and other lists that people prioritize manually.

## Implementation prompt

> Support dragging and button-based reordering and announce the item's new position.

## Sources and credits

[Atlassian Design · Accessible drag and drop](<https://atlassian.design/components/pragmatic-drag-and-drop/accessibility-guidelines/>)

## 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>Drag to Reorder · 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:#172724;color:#f5eed9}main{width:min(100%,680px);padding:clamp(15px,4vw,36px)}.board{background:#243931;border:1px solid #667566;padding:clamp(15px,4vw,30px);box-shadow:0 8px 30px #0e1e1d62}.header{display:flex;justify-content:space-between;align-items:center;gap:10px}.header .mono{color:#c5cfb3}h1{margin:6px 0 14px}.register{display:flex;gap:3px}.register i{width:12px;height:12px;border-radius:50%;background:#dd9d51}.register i:nth-child(2){background:#7aada0}.register i:nth-child(3){background:#de8679}.queue{list-style:none;padding:0;margin:0;display:grid;gap:7px}.row{display:flex;align-items:center;gap:12px;position:relative;padding:6px 6px 6px 0;background:#f2ead2;color:#243b33;border-left:8px solid var(--band);transition:transform .22s cubic-bezier(.2,.8,.28,1);min-height:61px}.row b{font:italic 700 23px/1 Georgia,serif}.name{display:block;font-size:16px}.detail{display:block;color:#4e5849;font-size:11px}.grab{width:36px;min-height:46px;flex:none;background:transparent;border:0;color:#536254;cursor:grab;touch-action:none;font-size:19px;line-height:1}.grab:active{cursor:grabbing}.row.lift{z-index:2;box-shadow:0 8px 18px #0a181b5c;transition:none}.controls{display:flex;gap:2px;margin-left:auto}.controls button{height:44px;width:39px;border:1px solid #bec2ad;background:#f8f4e6;font-size:16px}.controls button:disabled{color:#8f9884;border-color:transparent;background:none}.foot{margin-top:13px;min-height:24px;font-size:12px;color:#d3dcc4}@media(max-width:390px){.row{gap:6px;border-left-width:5px}.grab{width:31px}.controls button{width:33px}.row b{font-size:18px}.name{font-size:14px}}

@media(pointer:coarse){.controls button,.grab{min-width:44px;min-height:44px}}
html:is([data-motion-platform="ios"],[data-motion-platform="android"]) .controls button,
html:is([data-motion-platform="ios"],[data-motion-platform="android"]) .grab{min-width:44px;min-height:44px}
</style></head><body>

<main><section class="board"><div class="header"><span class="mono">Press order · Print studio</span><span class="register" aria-hidden="true"><i></i><i></i><i></i></span></div><h1>Print queue</h1><ol id="queue" class="queue" aria-label="Print order"></ol><p role="status" id="status" class="foot">Drag a handle or use the up and down buttons to reorder.</p></section></main>

<script>

const items=[['Field Dots','Ochre ink','#d7a35a'],['Tree Shadows','Green ink','#629781'],['Walker’s Lines','Coral ink','#c46f5b'],['Evening Type','Black ink','#63716d']];
const queue=document.querySelector('#queue'),status=document.querySelector('#status');let drag=null;
function nodes(){return Array.from(queue.children);}
function number(){nodes().forEach((el,i)=>{el.querySelector('b').textContent=String(i+1).padStart(2,'0');el.querySelector('.up').disabled=i===0;el.querySelector('.down').disabled=i===queue.children.length-1;});}
function commit(row,from,to,origin){
  const order=nodes(),before=new Map(order.map(el=>[el,el.getBoundingClientRect().top]));
  order.splice(from,1);order.splice(to,0,row);queue.replaceChildren(...order);number();
  const reduce=document.documentElement.classList.contains('motion-reduced')||matchMedia('(prefers-reduced-motion: reduce)').matches;
  if(!reduce)order.forEach(el=>{const offset=before.get(el)-el.getBoundingClientRect().top;if(offset)el.animate([{transform:'translateY('+offset+'px)'},{transform:'none'}],{duration:210,easing:'ease-out'});});
  (origin.disabled?row.querySelector('.grab'):origin).focus({preventScroll:true});
  status.textContent=row.querySelector('.name').textContent+' moved from position '+(from+1)+' to '+(to+1)+'.';
}
function cancel(e,accept=false){
  if(!drag||(e&&e.pointerId!==drag.id))return;
  const d=drag;drag=null;
  d.row.classList.remove('lift');nodes().forEach(el=>el.style.removeProperty('transform'));
  if(d.grab.hasPointerCapture(d.id))d.grab.releasePointerCapture(d.id);
  if(accept&&d.from!==d.to)commit(d.row,d.from,d.to,d.grab);
  else if(d.moved){status.textContent=accept?'Order unchanged.':'Move canceled.';d.grab.focus({preventScroll:true});}
}
for(const [title,ink,band] of items){
  const row=document.createElement('li');row.className='row';row.style.setProperty('--band',band);
  row.innerHTML='<button type="button" class="grab">⠿</button><b aria-hidden="true"></b><div><strong class="name"></strong><small class="detail"></small></div><div class="controls"><button class="up" type="button">↑</button><button class="down" type="button">↓</button></div>';
  row.querySelector('.name').textContent=title;row.querySelector('.detail').textContent=ink;
  const grab=row.querySelector('.grab');grab.setAttribute('aria-label',title+' Drag handle');grab.setAttribute('aria-describedby','status');
  for(const [cls,delta] of [['up',-1],['down',1]]){
    const button=row.querySelector('.'+cls);button.setAttribute('aria-label',title+(delta<0?' Move up':' Move down'));
    button.addEventListener('click',()=>{if(drag)return;const i=nodes().indexOf(row),to=i+delta;if(to>=0&&to<queue.children.length)commit(row,i,to,button);});
  }
  grab.addEventListener('keydown',e=>{if(drag)return;const delta=e.key==='ArrowDown'?1:e.key==='ArrowUp'?-1:0;if(delta){e.preventDefault();const i=nodes().indexOf(row),to=i+delta;if(to>=0&&to<queue.children.length)commit(row,i,to,grab);}});
  grab.addEventListener('click',e=>{if(e.detail===0)status.textContent='Use the arrow keys or the move buttons on the row.';});
  grab.addEventListener('pointerdown',e=>{if(drag||e.button!==0||!e.isPrimary)return;const positions=nodes().map(el=>el.offsetTop),from=nodes().indexOf(row);drag={row,grab,id:e.pointerId,y:e.clientY,from,to:from,positions,moved:false};grab.setPointerCapture(e.pointerId);});
  grab.addEventListener('pointermove',e=>{if(!drag||drag.id!==e.pointerId||drag.row!==row)return;const d=drag,dy=e.clientY-d.y;if(!d.moved&&Math.abs(dy)<3)return;d.moved=true;row.classList.add('lift');const offset=Math.max(d.positions[0]-d.positions[d.from],Math.min(dy,d.positions.at(-1)-d.positions[d.from]));const top=d.positions[d.from]+offset;
    d.to=d.positions.reduce((best,pos,i)=>Math.abs(pos-top)<Math.abs(d.positions[best]-top)?i:best,d.from);
    nodes().forEach((el,i)=>{let shift=0;if(i===d.from)shift=offset;else if(i>d.from&&i<=d.to)shift=d.positions[i-1]-d.positions[i];else if(i<d.from&&i>=d.to)shift=d.positions[i+1]-d.positions[i];el.style.transform='translateY('+shift+'px)';});
  });
  grab.addEventListener('pointerup',e=>cancel(e,true));grab.addEventListener('pointercancel',e=>cancel(e));grab.addEventListener('lostpointercapture',e=>cancel(e));
  queue.append(row);
}
document.addEventListener('keydown',e=>{if(e.key==='Escape'&&drag){e.preventDefault();cancel(null);}});
number();

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