Dragging that survives a finger
By the end you will have a dependency-free sortable list that survives a finger — Pointer Events with capture, touch-action rented to a grip, a movement threshold, drop-slot math, edge autoscroll, and a keyboard path with live announcements.
Why the drag dies under a finger
Under a finger, draggable="true" mostly does nothing: Chrome on Android has never fired dragstart from a touch, and Safari, which wired up DragEvent in iOS 15, wants a long-press and still competes with the system's own long-press menu. The dependable path on touch is Pointer Events — pointerdown, pointermove, pointerup — one event stream for mouse, finger and pen. This article builds a sortable list on that stream, layer by layer, and keeps the Drag and Drop API for the two jobs it still wins: dropping files and moving data between windows.
Interact with either card; the log shows what really fires.Reading this browser…Do not take that paragraph on faith. The two cards are wired to the two APIs, and the log records every event your browser actually fires, with the pointer type in parentheses. Drag with a mouse, then with a finger, and compare.
With a mouse, both lanes light up. On a phone, the right lane floods with pointermove (touch) while the left usually stays silent — and drag events carry no pointer information at all, so the log cannot even tell you which finger did it. The second readout reports what this browser claims about itself: navigator.maxTouchPoints, whether PointerEvent exists, whether touch-action parses. That is the honest way to write about touch support: test the device in front of you and keep the claims small.
Keep the events coming
A drag has a moving-target problem, but only for two of the three pointer types. Mouse and pen events are delivered to whatever sits under the pointer: on every pointermove the browser hit-tests the element tree at the pointer's coordinates and re-targets the event, so the instant your hand outruns the element — a small chip, a thin grip — the events stop reaching your listener and the drag freezes. Touch is the opposite: the Pointer Events spec requires the browser to implicitly capture every touch pointer to the element that received pointerdown, so a finger that rolls halfway off a small target keeps its stream anyway.
On a phone both chips follow your finger: the browser captures touch implicitly. With mouse or pen, stray and see which chip survives.The right chip calls setPointerCapture(event.pointerId) inside pointerdown, and that one call makes mouse and pen behave like touch already does. From then on the browser delivers every pointer event to that element until the press ends — outside the chip, outside the panel, outside the window. On a phone you cannot tell the two chips apart, and that is the lesson: the left chip is riding the implicit capture the browser grants every touch pointer, the right chip is renting the same guarantee explicitly for the pointer types that do not get it. Drag with a mouse and the asymmetry appears: leave the left chip and the drag ends on the spot, while the right chip holds every event until pointerup. It is the same three lines that keep sliders that fight back attached to a fast hand, and the first thing to check when mouse events seem to vanish mid-gesture, right after finding where your click really lands.
One level deeper. Re-targeting on every move is not a bug; it is what lets hover highlights follow a freely roaming mouse — and a pen roams the same way, which is why a drag that works on your phone can still die under a desktop pen until you add the call. Implicit capture exists because a finger is not roaming anything: it presses one spot and moves, so the spec pins the stream to the target of the press. While any capture is active, boundary events such as pointerover and pointerout stop firing as the pointer crosses other elements — one more sign that hit-testing is switched off for the duration of the gesture.
</> Capture in four listeners.Show code
grip.addEventListener('pointerdown', e => {
// touch is captured implicitly; this call covers mouse and pen
grip.setPointerCapture(e.pointerId);
drag = { y: e.clientY };
});
grip.addEventListener('pointermove', e => {
if (drag) item.style.transform =
`translate(0px, ${e.clientY - drag.y}px)`;
});
grip.addEventListener('pointerup', () => (drag = null));
grip.addEventListener('pointercancel', () => (drag = null));Who owns the finger
Now the real conflict. On a touchscreen your drag and the page's scroll are the same gesture — one finger, two claimants. The browser settles it by reading the CSS touch-action property on the element where the gesture starts. touch-action: none says "this element handles the pointer; never pan or zoom for it". Any looser value lets the browser take over, and when it does it fires pointercancel and you get no more moves.
grip: touch-action none · card body: touch-action autoOn a phone, try both surfaces. With the defaults — grip none, card auto — a grip drag is yours and a card-body drag scrolls the list, which is exactly the deal you want. Now turn the whole card to none: the list only scrolls in the gaps between rows, and on a dense list that feels broken. Hence the rule: touch-action: none on the drag handle, and only the handle. For a horizontal drag in a vertical page you rent less — touch-action: pan-y on the card lets vertical scrolls pass through and claims only sideways movement.
One level deeper. The browser reads touch-action once, when the gesture starts, and the pan decision normally runs on the compositor thread, ahead of your script. Setting the property from inside pointermove is too late; the gesture has already been promised to scrolling. pointercancel is your receipt: it means the pointer was taken away, not released, and the correct response is to restore state — order, transforms, classes — never to treat it as a drop.
Make movement prove intent
The grip is also a button — in the finished list it is literally a <button> — so a press that never moves must still land as a press. (This demo's grip is a bare <span> to keep the code short; fine for a throwaway, wrong to ship.) And fingers never hold still: Android defines a touch slop of 8 density-independent pixels, scaled to the screen, before a touch counts as movement, and iOS keeps a similar private constant. Your threshold plays the same role for your list.
state: idle — press the gripUnder the threshold the card stays put while the bar fills with travelled distance; cross it and the card commits, lifting and following from that moment. Release early and the gesture resolves as a tap, and the state line says so. Drag the threshold to 24 and the list feels stubborn; drop it to 3 and taps start lifting cards. Eight pixels is a good default precisely because it matches the slop users already know from the rest of their phone.
</> A threshold is one if-statement.Show code
let press = null;
grip.addEventListener('pointerdown', e => {
grip.setPointerCapture(e.pointerId);
press = { x: e.clientX, y: e.clientY, live: false };
});
grip.addEventListener('pointermove', e => {
if (!press || press.live) return;
const moved = Math.hypot(e.clientX - press.x, e.clientY - press.y);
if (moved >= 8) { // your threshold
press.live = true; // only now lift the card
press.x = e.clientX; press.y = e.clientY;
}
});Watch the browser pick the slot
While the card follows your finger, a second question runs on every move: where would it land? The rule is one line — the pointer has passed every midpoint above it — but believing it is easier when you can watch it. Drag any row slowly.
Teal dots: row midpoints. Peach dot: your pointer. Peach line: the chosen slot.The count of midpoints above the pointer is the insertion index, printed live. Rows below the slot slide down by exactly one row height — a transform, never a layout change — so the gap opens without the browser recomputing geometry. When the pointer sits between two midpoints, the slot below it wins; move a pixel and you see the line jump.
</> The whole slot rule.Show code
// pointer y against every other row's midpoint
const rects = others.map(el => el.getBoundingClientRect());
let index = 0;
for (const r of rects) {
if (pointerY > r.top + r.height / 2) index++;
}
// open the gap without touching layout
others.forEach((el, i) => {
el.style.transform = i >= index ? 'translate(0px, 44px)' : '';
});Drag a row against the top or bottom edge and hold. The scroller keeps going while your finger stands still — the only way long lists work. A requestAnimationFrame loop measures how far the pointer sits inside a 56-pixel edge band and scrolls proportionally, then re-runs the slot math against the new rectangles. It is the same per-frame loop we dissected in timers that miss the frame; autoscroll driven by setTimeout stutters exactly as that article predicts.
One level deeper. Every animated property here is transform. A transform never triggers layout, so reading rectangles after writing transforms is cheap and truthful — the dots are the browser's real boxes, not a drawing of a claim. And if pointercancel arrives mid-drag (a notification, a palm, a scroll steal), this demo restores the old order instead of committing; a cancelled drag must never count as a drop.
Reorder without dragging
Everything above serves one input style. WCAG 2.2 criterion 2.5.7, Dragging Movements (Level AA), requires that anything doable by dragging also be doable with a single pointer without dragging — unless the drag itself is essential, which reordering a list is not. The up and down buttons on each row are that path: tap, tap, done. Keyboard access is a separate, older requirement (2.1.1 Keyboard), which is why the grip is a real button: focus it, press Enter or Space to pick the row up, arrow keys to move it, Enter or Space to drop, Escape to put it back where it was.
Drag a grip, tap an arrow, or focus a grip and press Enter or Space.The transcript is not decoration. It logs every message the component generates, while the debounced live region sends only the last one of each burst — hold an arrow key down and the transcript floods while a screen reader says a single sentence. That gap is the design, and it is the honest way to audit the speech path with your eyes: each drag, button press and keyboard move names the row and its new position, and a cancelled keyboard drag announces the restore.
One level deeper. Announcements go to a visually hidden element with aria-live="polite", debounced by 350 milliseconds. Holding an arrow key fires a move per key repeat; announcing each one makes screen readers talk over themselves and cut off mid-sentence. Debouncing collapses the burst into one final message — the same trade-off as choosing debounce on a timeline, applied to ears instead of networks.
</> One announcement per burst.Show code
let timer = 0;
function say(message) {
clearTimeout(timer);
timer = setTimeout(() => {
liveRegion.textContent = message; // aria-live="polite"
}, 350);
}
// a burst of arrow presses becomes one announcement
say('Moved Draft to position 3 of 5');When to drag and when not to
So when is the old API the right tool? When you need the parts of it Pointer Events cannot reach. It speaks to the operating system's drag layer: you can receive real files through dataTransfer.files, accept drags coming from other applications, drag a text selection or an image out of the page, and move data between two browser windows. A file drop zone with the Drag and Drop API is a dozen lines and covers every source a desktop has — pair it with a plain file input for people who tap instead (MDN's Drag and Drop guide maps the events).
For reordering, Pointer Events win on every axis this article touched: one code path for mouse, finger and pen, a threshold and a drag image you control, no long-press roulette, and a page that still scrolls because you only rented the grip. The price is everything you just built — capture, touch-action, cancellation, slot math, autoscroll, and the accessibility layer. If you do not want to own that surface forever, a maintained library that does is a reasonable answer.
People who request reduced motion get the same list here: the shifting rows lose their transition and keep their function, because nothing in the component is decorative. Dragging is a convenience, not the contract — the buttons are the contract, the keyboard path is the contract, and the drag politely cancels whenever the browser takes the gesture back.
Ship the boring path first. Make the buttons and the keyboard mode work before you write a line of drag code. Then the drag is a bonus you can afford to break, not the only way through your interface.
Quick answers
Why does HTML5 drag and drop not work on touch devices?
The HTML5 Drag and Drop API was built for the mouse. Chrome on Android has never fired dragstart from a touch, and Safari only wired up DragEvent in iOS 15 — where it wants a long-press and still competes with the system's long-press menu. Use Pointer Events for touch dragging, and keep the old API for the jobs it still wins: dropping files and moving data between windows.
How do you make drag and drop work on mobile in JavaScript?
Use Pointer Events instead of the Drag and Drop API. Call setPointerCapture(event.pointerId) in pointerdown — a touch pointer is captured implicitly anyway, and this one call gives mouse and pen the same behavior — set touch-action: none on the drag handle only so the page still scrolls elsewhere, and require about 8 pixels of movement before a press becomes a drag so taps still work. Then compute the drop slot from row midpoints and autoscroll near the edges.
Where should touch-action: none be set for drag and drop?
touch-action tells the browser, when a gesture starts, whether to pan or zoom or leave the pointer to your script. none claims all movement, so the browser never scrolls for that element — and fires pointercancel if it takes over. Put it on the drag handle only; set on the whole card, the list scrolls only in the gaps between rows. For horizontal drags, pan-y is enough.
What does pointercancel mean during a drag?
pointercancel fires when the browser takes the pointer away mid-gesture — typically because scrolling took over the touch, a notification arrived, or a palm landed on the screen. It is not a release, so treat it as an abort: restore the previous order, transforms and classes rather than committing a drop. That is also why touch-action must be set before the gesture, not inside pointermove.
How do I make a drag-and-drop list accessible?
WCAG 2.2 criterion 2.5.7 (Dragging Movements, Level AA) requires anything doable by dragging to also be doable with a single pointer without dragging, and 2.1.1 requires keyboard access. Give each row up and down buttons, and make the grip a real button: Enter or Space picks the row up, arrows move it, Enter or Space drops, Escape restores. Announce changes through an aria-live region debounced by about 350 milliseconds.