Skip to content
IndexRequest a UIAboutContact

Drag to Reorder

A sortable list where rows are dragged by a handle and the others move aside live.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Build a four-item sortable list (Design, Build, Test, Ship), 280px wide, each row 48px tall with a six-dot drag handle on the left (a button, 44px wide, touch-action none) and a 14px label. On pointerdown on a handle, capture the pointer and remember the offset between pointer and row top. While moving, set the row transform so it follows the pointer; when the pointer crosses the vertical midpoint of a sibling, move the row in the DOM before or after that sibling and recompute the transform from its new natural position. Style the dragged row with a stronger border, a light shadow and a z-index. On release animate the transform back to 0 in 200ms. Keyboard: with the handle focused, Alt+ArrowUp and Alt+ArrowDown move the row, keep focus on the handle and announce "Moved to position N of 4" in an aria-live region. Under prefers-reduced-motion remove transitions.

About this pattern

Definition

A list whose items can be rearranged by dragging. The dragged item follows the pointer while the others shift to show where it will land.

Purpose & UX principles

  • Lets people prioritise or arrange items directly.
  • A dedicated handle avoids accidental drags and keeps scrolling usable.
  • Keyboard users reorder with Alt and the arrow keys on the handle, and the change is announced.

Interaction states

  • Rest, hover (handle darkens), dragging (row lifted with shadow), dropped, focus-visible on the handle.

Motion specification

  • While dragging the row follows the pointer exactly; neighbours move instantly as the order changes.
  • The lift shadow fades in over 150ms and the row settles in 200ms on release.
  • Reduced motion: no shadow transition and an instant drop.

Responsive behaviour

  • Rows are 48px tall with a 44px handle target.
  • On touch the handle uses touch-action: none so the drag does not scroll the page.

Code

HTML
<div class="box">
  <ul class="sl" id="sl"></ul>
  <p class="live" id="live" aria-live="polite">Drag the handles, or use Alt + arrow keys.</p>
</div>

Related patterns

Swipe to Delete

↗
Swipe to DeleteGestures & Touch

Selectable Card

↗
Selectable CardCards & Containers

Bottom Sheet

↗
Bottom SheetGestures & Touch