Interactivity

Touch Action

Utilities for controlling how an element can be scrolled and zoomed on touchscreens.

Quick reference

Class
Properties
touch-autotouch-action: auto;
touch-nonetouch-action: none;
touch-pan-xtouch-action: pan-x;
touch-pan-lefttouch-action: pan-left;
touch-pan-righttouch-action: pan-right;
touch-pan-ytouch-action: pan-y;
touch-pan-uptouch-action: pan-up;
touch-pan-downtouch-action: pan-down;
touch-pinch-zoomtouch-action: pinch-zoom;
touch-manipulationtouch-action: manipulation;

Basic usage

Setting the touch action

Use the touch-{action} utilities to control how an element can be scrolled (panned) and zoomed (pinched) on touchscreens.

Touch Action - 图1

Try panning these images on a touchscreen

Touch Action - 图2

  1. <div class="w-full h-48 overflow-auto touch-auto ...">
  2. <img class="w-[150%] max-w-none h-auto" src="..." />
  3. </div>
  4. <div class="w-full h-48 overflow-auto touch-none ...">
  5. <img class="w-[150%] max-w-none h-auto" src="..." />
  6. </div>
  7. <div class="w-full h-48 overflow-auto touch-pan-x ...">
  8. <img class="w-[150%] max-w-none h-auto" src="..." />
  9. </div>
  10. <div class="w-full h-48 overflow-auto touch-pan-y ...">
  11. <img class="w-[150%] max-w-none h-auto" src="..." />
  12. </div>

Applying conditionally

Hover, focus, and other states

Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use focus:touch-pan-x to only apply the touch-pan-x utility on focus.

  1. <div class="focus:touch-pan-x">
  2. <!-- ... -->
  3. </div>

For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.

Breakpoints and media queries

You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:touch-pan-x to apply the touch-pan-x utility at only medium screen sizes and above.

  1. <div class="md:touch-pan-x">
  2. <!-- ... -->
  3. </div>

To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.