Before Pointer Events, handling input meant writing the same logic three times: mouse events, touch events and pen events, each with its own quirks. Pointer Events unify all of them into one set of events. A pointerdown is a pointerdown whether it came from a mouse, a finger or a stylus — and your code does not need to care which one it was.
The main events mirror the mouse ones you already know: pointerdown, pointermove, pointerup and pointercancel. The pointerType property tells you which device produced the event, so you can still special-case touch or pen when you need to.
const box = document.querySelector("#drag-box"); box.addEventListener("pointerdown", (event) => { console.log("Pressed with:", event.pointerType); // "mouse", "touch" or "pen" console.log("At:", event.clientX, event.clientY); }); The real power shows in drag-and-drop. With mouse events, a drag breaks when the pointer leaves the element. With setPointerCapture(), the element keeps receiving events until the pointer is released, even if it moves outside — which makes dragging smooth and reliable on every device.
let dragging = false; box.addEventListener("pointerdown", (event) => { dragging = true; box.setPointerCapture(event.pointerId); }); box.addEventListener("pointermove", (event) => { if (!dragging) return; box.style.left = event.clientX + "px"; box.style.top = event.clientY + "px"; }); box.addEventListener("pointerup", () => { dragging = false; }); Pointer Events also solve a classic mobile headache: the browser's own touch gestures fighting your code. touch-action: none in CSS tells the browser not to scroll or zoom when the user drags on your element, so your pointer handlers get every movement.
#drag-box { touch-action: none; /* let JavaScript handle all movement */ } One more useful property: pressure tells you how hard a pen or touch is pressing, from 0 to 1. That is how drawing apps vary line thickness — and it works with the same event handlers as everything else.
If you are still writing separate mouse and touch handlers, switch to Pointer Events. One set of handlers, one drag implementation, and your code works with a mouse, a finger and a stylus without a single extra branch.


