The CSS touch-action property controls how the browser handlesdefault touch gestures such as panning, zooming, and double-tap zoom. It is essential for building touch-friendly UI components, sliders, drag-and-drop, drawing canvases, and mobile web apps.
Note
β Required for smooth dragging & gesture handling
β Prevents conflicts between browser gestures and your JavaScript
π¦ Syntax
touch-action syntax
touch-action: auto | none | pan-x | pan-y | pan-left | pan-right | pan-up | pan-down | pinch-zoom | manipulation;π What Does touch-action Control?
- Panning (scrolling) horizontally or vertically
- Pinch zoom gestures
- Double-tap zoom
- Browser UI behaviors (like navigation gestures)
π¨ Value Breakdown with Examples
1οΈβ£ touch-action: auto;
Default β the browser handles all gestures normally.
auto
.element {
touch-action: auto;
}2οΈβ£ touch-action: none; (Most restrictive)
Disables all built-in gestures β perfect for custom drag, drawing, or gesture apps.
none
canvas,
.draggable {
touch-action: none; /* Prevents scroll, pinch, zoom */
}Note
3οΈβ£ touch-action: pan-x;
Allows horizontal scrolling only. Vertical swipes will NOT scroll the page.
pan-x
.horizontal-scroll {
touch-action: pan-x;
}4οΈβ£ touch-action: pan-y;
Allows vertical scrolling only. Horizontal gestures won't scroll.
pan-y
.vertical-scroll {
touch-action: pan-y;
}5οΈβ£ Directional panning
Directional
.left-pan-only { touch-action: pan-left; }
.right-pan-only { touch-action: pan-right; }
.up-pan-only { touch-action: pan-up; }
.down-pan-only { touch-action: pan-down; }Useful for specific gesture-based interactions.
6οΈβ£ touch-action: pinch-zoom;
Allows only pinch-zoom, but disables other gestures like double-tap zoom.
pinch-zoom
img {
touch-action: pinch-zoom;
}7οΈβ£ touch-action: manipulation;
Enables only simple actions like taps β disables double-tap zoom. Improves mobile UI responsiveness.
manipulation
button, a {
touch-action: manipulation;
}Note
π Combining Values
Combined example
.map {
touch-action: pan-x pan-y pinch-zoom;
}Good for map apps: allow scrolling & zooming but block double-tap zoom.
π§ͺ Real-World Use Cases
1οΈβ£ Drag-and-Drop UI (Disable Native Touch)
Drag handles
.drag-item {
touch-action: none;
}Prevents the browser from stealing the drag gesture.
2οΈβ£ Image Gallery Slider (Lock Vertical Scroll)
Horizontal slider
.image-slider {
touch-action: pan-x;
}3οΈβ£ Drawing Apps (Canvas)
Drawing canvas
canvas {
touch-action: none; /* Prevents page from moving while drawing */
}4οΈβ£ Mobile Navigation Gestures
Navigation block
.edge-gesture-area {
touch-action: none;
}β οΈ Common Mistakes
- β Using touch-action on non-touch devices β it simply has no effect
- β Setting none everywhere and breaking scroll behavior
- β Using pan-x or pan-y on elements that shouldnβt interfere with scroll
- β Forgetting that touch-action is required for Pointer Events to work reliably
π₯ Summary
touch-action gives you precise control over how touch gestures behave, making it essential for interactive components, sliders, maps, drawing apps, and mobile web experiences.