Interactivity
Utilities for controlling how an element can be scrolled and zoomed on touchscreens.
Use the touch-*
utilities to control how an element can be scrolled (panned) and zoomed (pinched) on touchscreens.
Try panning these images on a touchscreen
touch-auto
touch-none
touch-pan-x
touch-pan-y
<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>
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.
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.