Interactivity
Touch Action
Utilities for controlling how an element can be scrolled and zoomed on touchscreens.
Quick reference
Class | Properties |
---|---|
touch-auto | touch-action: auto; |
touch-none | touch-action: none; |
touch-pan-x | touch-action: pan-x; |
touch-pan-left | touch-action: pan-left; |
touch-pan-right | touch-action: pan-right; |
touch-pan-y | touch-action: pan-y; |
touch-pan-up | touch-action: pan-up; |
touch-pan-down | touch-action: pan-down; |
touch-pinch-zoom | touch-action: pinch-zoom; |
touch-manipulation | touch-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.
Try panning these images on a touchscreen
<div class="w-full h-48 overflow-auto touch-auto ...">
<img class="w-[150%] max-w-none h-auto" src="..." />
</div>
<div class="w-full h-48 overflow-auto touch-none ...">
<img class="w-[150%] max-w-none h-auto" src="..." />
</div>
<div class="w-full h-48 overflow-auto touch-pan-x ...">
<img class="w-[150%] max-w-none h-auto" src="..." />
</div>
<div class="w-full h-48 overflow-auto touch-pan-y ...">
<img class="w-[150%] max-w-none h-auto" src="..." />
</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.
<div class="focus:touch-pan-x">
<!-- ... -->
</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.
<div class="md:touch-pan-x">
<!-- ... -->
</div>
To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.