Drag & Drop List
A drag-and-drop sortable list using the native HTML5 Drag and Drop API. Items animate to their new positions with smooth CSS transitions. Zero dependencies.
Code
Drag & Drop List
A smooth drag-and-drop sortable list using the native HTML5 Drag and Drop API — no libraries, no dependencies. Items reorder in real-time as you drag over them.
How it works
- Each
<li>hasdraggable="true"and a drag handle icon dragstartstores a reference to the dragged elementdragoveron sibling items determines insertion point (before or after) usinggetBoundingClientRectmidpoint- The list re-inserts the dragged node in real-time via
insertBefore/appendChild - Visual feedback: dragged item gets
.draggingopacity; hovered items get a top/bottom border hint
Accessibility note
The native drag API has limited keyboard/screen-reader support. For production, pair with a keyboard-accessible fallback (arrow keys to move items).
When to use it
- Todo / task list ordering
- Kanban column sorting
- Dashboard widget rearrangement