webdevpuneet.com

Bootstrap Drag-to-Reorder List — Free HTML CSS JS Snippet

Bootstrap Drag-to-Reorder List · Layouts · Plain HTML, CSS & JS · Live preview

CategoryLayouts

Copy & paste

Source Code

<div class="container py-5 d-flex justify-content-center">
  <div class="card bsdrag-card">
    <div class="card-body p-3">
      <h6 class="fw-bold mb-2">Priority order</h6>
      <ul class="list-unstyled mb-0" id="bsdragList"></ul>
      <p class="small text-muted mt-2 mb-0">Drag the handle to reorder.</p>
    </div>
  </div>
</div>

Extend with AI

Take This Snippet Further With AI

The AI prompt for this one is for Patreon supporters ($3 a month), along with a site with no ads. Supporters enter the passcode once and it is remembered in this browser.

· Become a supporter

What's included

Features

Uses the genuine native HTML5 Drag and Drop API, not a custom pointer-events reimplementation
Reordering is a real array splice-out/splice-in, not a purely visual DOM shuffle disconnected from the data
Rank numbers are rendered from the array's live order, always accurate after every reorder
A clear visual drop-target indicator shows exactly where an item would land before releasing
Dropping an item onto its own current position is correctly treated as a no-op

About this UI Snippet

Bootstrap Drag-to-Reorder List — HTML, CSS & JavaScript

Screenshot of the Bootstrap Drag-to-Reorder List snippet rendered live

This uses the browser's actual native HTML5 Drag and Drop API — draggable="true" on each row plus dragstart/dragover/drop listeners — rather than a pointer-events-based reimplementation, the same approach this collection's bootstrap-kanban-board-cards uses for moving cards between columns, applied here to reordering within a single list instead.

The one line that's easy to leave out and silently breaks everything is e.preventDefault() inside the dragover handler — without it, the browser's default behavior refuses the drop entirely, and the drop event never fires on the element at all, no matter how correct the rest of the drop logic is.

The actual reordering is a genuine array move, not a DOM-only shuffle: items.splice(fromIndex, 1) removes the dragged item from its old position, and items.splice(toIndex, 0, moved) reinserts it at the new one, then render() rebuilds the whole list from that updated array — including the visible rank number next to each row, which is what makes the numbers 1 through 4 always correctly reflect the list's true current order rather than needing separate logic to keep them in sync with whatever the drag-and-drop just did visually.

Step by step

How to Use

  1. 1
    Load the snippetFour priority items list in order, each numbered 1 through 4 with a drag handle icon.
  2. 2
    Press and drag the handle on item 3It fades to semi-transparent while dragging, and rows show a blue top border as you hover over a valid drop target.
  3. 3
    Drop it above item 1The list reorders immediately, and every row's rank number updates to reflect the new true order.
  4. 4
    Drag item 1 (now originally item 3) down to the bottomIt moves correctly, and the numbering stays accurate throughout.
  5. 5
    Try dropping an item onto itselfNothing changes — dropping a row where it already is is correctly treated as a no-op.

Real-world uses

Common Use Cases

Priority lists, to-do ordering, and custom sort preferences
Pairs with bootstrap-todo-list-app for a fully reorderable task list.
Letting a reorder be undone as easily as a delete
Pair with bootstrap-undo-action-toast so removing an item from this same list offers the same safety net as reordering it does.
Dashboard widget or navigation menu ordering
Let a user customize the order of items in a settings or layout-configuration screen.
Playlist, queue, and step-ordering interfaces
Any list where the sequence itself carries meaning benefits from a direct drag-to-reorder interaction.

Got questions?

Frequently Asked Questions

Browsers refuse a drop by default unless something explicitly opts in during dragover — omitting that one call means the drop event never fires at all on that element, regardless of how correct the rest of the drop-handling logic is.

Yes — the reorder is a real Array.splice() operation on the items array itself, and render() rebuilds the entire list (including the rank numbers) from that array afterward, so the visible order is never just a disconnected DOM rearrangement.

The native HTML5 Drag and Drop API has inconsistent and often poor support on mobile touch browsers; a production implementation targeting mobile should use a pointer-events-based drag library or fallback instead of relying on this API alone.

Yes. Keep items as an array in component state, and perform the same splice-based reorder inside your drop handler, updating state immutably (a new array, not a mutated one) per your framework's conventions.