CSS components

Drag Handle Reorder List Generator

Create a sortable list where people drag items by a grip handle. It works with a mouse, on touch screens and with the keyboard, and it tells you the new order when something moves.

Try it in the preview: drag the grip, or focus a grip with Tab and press the up and down arrow keys.

Live preview

Runs entirely in your browser. Nothing is uploaded to any server.

Why use this reorder list

Works everywhere

Pointer events handle mouse, pen and touch with one code path.

Keyboard accessible

Arrow keys move items, with screen reader announcements.

No library

Under 80 lines of plain JavaScript.

How to build a drag-to-reorder list

  1. List your itemsEnter one item per line in the order they should start.
  2. Style the listChoose the handle side, icon, density, colours and numbering.
  3. Copy the codeListen for the reorder event to save the new order.

Why pointer events instead of HTML drag and drop

The native HTML drag and drop API does not work on most touch screens and gives little control over the dragged item. This component uses pointer events instead: the handle captures the pointer, and as it moves the item is inserted before the first sibling whose middle is below the pointer.

Only the handle starts a drag, so text inside items can still be selected and links still work. touch-action: none on the handle stops the page from scrolling while you drag on a phone.

Live region

Each move is announced, for example "moved to position 2 of 5".

Numbering

Position numbers update automatically after every move.

reorder event

event.detail holds the item texts in their new order.

Drag reorder list FAQ

Does it work on phones and tablets?

Yes. Pointer events cover touch, and the handle disables scrolling only while you drag it.

How do I save the new order?

Listen for the reorder event on the list. Its detail is an array of item texts, or you can read data attributes from the items.

Can keyboard users reorder items?

Yes. Tab to a handle and press the up or down arrow key. Focus stays on the handle so you can keep moving the item.

Can I drag an item by its text?

Only the handle starts a drag. This avoids accidental moves and keeps text selection and links working.

Does the list scroll while dragging?

Auto-scrolling is not included. For very long lists, keep the list in a scrollable area or add auto-scroll in the pointermove handler.

Try other CSS component tools

More free tools from My Panda Toolbox.