Drag & Drop Snippets — Free HTML CSS JS Sortable & Draggable UI Examples

43 snippets tagged Drag & Drop · Live preview · Exports to React, Vue, Angular & Tailwind

What's included

Features

Sortable lists and kanban columns with live placeholder positioning
File dropzones with dragover styling, type filtering and paste support
Reorderable table rows and columns that persist their new order
Pointer-event dragging that works identically with mouse, touch and pen
Keyboard-accessible reordering as a first-class alternative, not an afterthought

About this tag

Drag & Drop Snippets — 43 Free Sortable & Draggable UI Examples

Dragging is direct manipulation: the user moves the thing itself rather than describing the move to a form. These snippets cover both mechanisms — the native HTML5 drag events for file drops and cross-container moves, and pointer-event dragging for the smooth, cancellable reordering that lists and boards need.

Each one handles the details that separate a real implementation from a demo: a placeholder showing where the item will land, auto-scroll near the edges, a cancel path on Escape, and a keyboard-accessible alternative for people who cannot drag at all.

Two different APIs for two different jobs

The HTML5 drag-and-drop API (draggable, dragstart, dragover, drop) is the only mechanism that receives files dragged in from the desktop or elements dragged between browser windows — nothing else can see those events. Pointer events, by contrast, give full control over the dragged element's visual position on every move, which is what in-page sortable lists and kanban boards actually need. Reaching for the wrong one is the most common cause of a drag feature that half-works.

The placeholder is what makes reordering legible

Without a visible gap showing where an item will land, a drag operation is guesswork until the user releases. Every sortable snippet here computes the insertion point continuously as the pointer moves — usually by comparing the pointer position against the midpoints of sibling elements — and shows a placeholder there, so the drop location is obvious before the drop happens.

Auto-scroll near the edges

A list or board longer than the viewport needs to scroll while an item is being dragged toward its edge, or reordering is limited to whatever is currently visible. These snippets detect the pointer entering a margin near the container's top or bottom and scroll the container at a speed proportional to how close the pointer is to the edge, stopping the moment the pointer moves back toward the centre.

Escape, and the keyboard path that is not optional

A cancel-on-Escape handler that returns the dragged item to its original position covers the case where a user changes their mind mid-drag. The more important requirement is a fully separate keyboard path — focus the item, then move it with an arrow-key or button-based control, announcing the new position through an aria-live region — because drag-only reordering is entirely unusable without a mouse, which makes it one of the more common accessibility failures in board and list UIs.

Real-world uses

Common Use Cases

Kanban and task boards
Moving a card between columns is the interaction the whole board pattern exists for.
File upload dropzones
Drop, click and paste should all reach the same handler — users try whichever one they learned first.
Priority and playlist ordering
Dragging expresses relative order far faster than typing numbers into a position field.
Dashboard and layout builders
Draggable panels let a user arrange their own workspace instead of accepting yours.

Got questions?

Frequently Asked Questions

HTML5 drag-and-drop for files from the desktop and for drops between windows — it is the only API that receives those. Pointer events for in-page reordering, because you control the visuals completely and it behaves the same on touch, where the native drag API is effectively unusable.

Pair every drag with a keyboard path: focus the item, then move it with Ctrl+Arrow or a "move up / move down" control, announcing the new position through an aria-live region. Drag-only reordering is unusable with a keyboard, a screen reader, or a tremor — and it is one of the most common accessibility failures in board UIs.

Usually because a child element fires dragleave as the pointer crosses it. Track a counter that increments on dragenter and decrements on dragleave, and only remove the highlight when it reaches zero — or set pointer-events: none on the children.

No. Every snippet is plain HTML, CSS and vanilla JavaScript that runs in any page — a static file, a WordPress theme, a Rails view, anything. When you do want a framework version, the editor exports each snippet as a React component, a React + Tailwind component, a standalone Tailwind HTML file, a Vue 3 single-file component or an Angular standalone component.

Yes — copy, modify and ship them in personal or commercial work, with no attribution required and no licence to track.

Yes. Every snippet opens in a live editor with separate HTML, CSS and JS panels and a preview that updates as you type. Check it at mobile, tablet and desktop widths, then copy the code or export it in your framework of choice.