CSS touch-action Property
The CSS touch-action property specifies which touchscreen gestures a browser is allowed to handle on an element.
It controls browser-managed gestures such as horizontal and vertical panning, pinch zooming, and certain double-tap zooming behaviors. The property is particularly useful for touch-enabled interfaces, custom gesture controls, interactive maps, and drawing applications that use Pointer Events.
touch-action Syntax
The touch-action property accepts keywords that determine which browser-managed touch gestures are permitted.
Basic Syntax
.example {
touch-action: auto;
}
Available Values
.example {
touch-action: auto;
}
.example {
touch-action: none;
}
.example {
touch-action: manipulation;
}
.example {
touch-action: pan-x;
}
.example {
touch-action: pan-y;
}
.example {
touch-action: pan-left;
}
.example {
touch-action: pan-right;
}
.example {
touch-action: pan-up;
}
.example {
touch-action: pan-down;
}
.example {
touch-action: pinch-zoom;
}
Combined Values
.example {
touch-action: pan-x pan-y;
}
.example {
touch-action: pan-x pinch-zoom;
}
.example {
touch-action: pan-y pinch-zoom;
}
.example {
touch-action: pan-left pan-up;
}
.example {
touch-action: pan-right pan-down pinch-zoom;
}
CSS-Wide Keywords
.example {
touch-action: initial;
}
.example {
touch-action: inherit;
}
.example {
touch-action: unset;
}
.example {
touch-action: revert;
}
.example {
touch-action: revert-layer;
}
Invalid Examples
.example {
touch-action: scroll;
}
.example {
touch-action: zoom;
}
.example {
touch-action: auto none;
}
.example {
touch-action: pan-x, pan-y;
}
.example {
touch-action: 50%;
}
The property does not accept lengths, percentages, or comma-separated lists. The keywords auto, none, and manipulation must be used individually.
Property Values
| Value | Description |
|---|---|
auto |
Allows the browser to handle its supported touch gestures normally. |
none |
Disables browser-managed panning and zooming gestures that start on the element. |
manipulation |
Allows panning and pinch zooming while disabling additional nonstandard gestures such as double-tap zooming. |
pan-x |
Allows browser-managed horizontal panning. |
pan-y |
Allows browser-managed vertical panning. |
pan-left |
Allows panning that begins with a leftward gesture. |
pan-right |
Allows panning that begins with a rightward gesture. |
pan-up |
Allows panning that begins with an upward gesture. |
pan-down |
Allows panning that begins with a downward gesture. |
pinch-zoom |
Allows browser-managed pinch zooming. |
| Combined values | Allows compatible panning and zooming gestures specified by space-separated keywords. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | auto |
| Inherited | No |
| Applies to | Elements that support the CSS width and height properties |
| Computed value | As specified |
| Animation type | Discrete |
| Percentages | Not accepted |
| Specification | Pointer Events Level 3 |
Note: Although the property is not inherited, the browser considers applicable touch-action values on ancestors when determining which gestures are permitted.
How It Works
Browsers normally interpret touchscreen movements as gestures such as scrolling or zooming. The touch-action property tells the browser which of those gestures it may handle.
Step 1: Identify the Interactive Element
<div class="touch-area">
Touch or drag within this area.
</div>
Step 2: Choose the Allowed Gestures
.touch-area {
touch-action: pan-y;
}
The browser may handle vertical panning that begins on the element, while horizontal panning is not permitted by this declaration.
Step 3: Restrict Browser Gestures
.touch-area {
touch-action: none;
}
The browser is instructed not to handle normal panning or zooming gestures that begin on the element.
Step 4: Allow Specific Gestures
.touch-area {
touch-action: pan-y pinch-zoom;
}
Vertical panning and pinch zooming are permitted, while horizontal panning is restricted.
Ancestor Elements
When a gesture begins, the browser evaluates the applicable touch-action values on the touched element and relevant ancestors. The permitted gestures are determined by their intersection, up to the relevant gesture-handling ancestor.
Gesture Initialization
The browser determines allowed gestures when the gesture starts. Changing touch-action after a gesture has begun does not change the handling of that active gesture.
The auto Value
The auto value allows the browser to handle supported touch gestures normally.
Basic Example
.touch-area {
touch-action: auto;
}
Default Behavior
Because auto is the initial value, most elements allow browser-managed gestures without an explicit declaration.
Scrollable Content
.scroll-panel {
overflow-y: auto;
touch-action: auto;
}
The browser can use its normal touch scrolling behavior when the element is scrollable.
Restoring Default Behavior
.touch-area {
touch-action: none;
}
.touch-area.allow-gestures {
touch-action: auto;
}
Important Consideration
An element with touch-action: auto may still be affected by more restrictive values on its ancestors.
The none Value
The none value prevents the browser from handling its normal panning and zooming gestures that begin on the element.
Basic Example
.drawing-area {
touch-action: none;
}
Custom Drawing Surface
<canvas class="drawing-area" width="400" height="250"></canvas>
CSS Example
.drawing-area {
display: block;
max-width: 100%;
border: 1px solid #94a3b8;
touch-action: none;
}
The browser does not use gestures starting on the canvas for normal panning or zooming, allowing application code to interpret pointer movements.
Pointer Events Are Still Available
The none value does not disable pointer event listeners. Applications can still respond to pointer input.
When to Use none
Use none for small, dedicated interactive regions that require custom handling of touch movements.
Accessibility Warning
Disabling browser-managed zooming can make content harder to use for people who need magnification. Avoid applying touch-action: none to entire pages or large content regions.
The manipulation Value
The manipulation value permits panning and pinch zooming while disabling additional nonstandard gestures, including double-tap zooming.
Basic Example
.button {
touch-action: manipulation;
}
Touch-Friendly Button
<button class="touch-button" type="button">Select Option</button>
CSS Example
.touch-button {
padding: 12px 20px;
cursor: pointer;
touch-action: manipulation;
}
Equivalent Gesture Permissions
.touch-button {
touch-action: pan-x pan-y pinch-zoom;
}
The manipulation keyword is an alias for allowing horizontal panning, vertical panning, and pinch zooming.
Double-Tap Behavior
Disabling double-tap zooming can help browsers respond to taps without waiting to determine whether another tap is coming. The actual response depends on the browser.
When to Use manipulation
Use it on interactive controls where normal scrolling and pinch zooming should remain available but double-tap zooming is unnecessary.
The pan-x Value
The pan-x value permits browser-managed horizontal panning.
Basic Example
.horizontal-scroll {
touch-action: pan-x;
}
Horizontal Scrolling Container
.horizontal-scroll {
display: flex;
gap: 12px;
overflow-x: auto;
overflow-y: hidden;
touch-action: pan-x;
}
HTML Example
<div class="horizontal-scroll">
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
</div>
Horizontal Gesture Behavior
Horizontal panning is permitted. Vertical panning and pinch zooming are not included in the allowed gestures unless separately specified.
Allowing Pinch Zooming
.horizontal-scroll {
touch-action: pan-x pinch-zoom;
}
When to Use pan-x
Use pan-x when horizontal panning should be handled by the browser and other touch gestures need to be restricted.
The pan-y Value
The pan-y value permits browser-managed vertical panning.
Basic Example
.vertical-scroll {
touch-action: pan-y;
}
Vertical Scrolling Container
.vertical-scroll {
max-height: 250px;
overflow-y: auto;
touch-action: pan-y;
}
Allowing Pinch Zooming
.vertical-scroll {
touch-action: pan-y pinch-zoom;
}
Horizontal Swipe Interface
.swipe-card {
touch-action: pan-y;
}
Allowing vertical browser panning while reserving horizontal gestures can be useful for custom swipe interactions implemented with JavaScript.
When to Use pan-y
Use pan-y when vertical scrolling should remain available while horizontal touch movements are handled separately.
Directional Panning Values
The directional panning keywords restrict browser-managed panning based on the initial direction of the gesture.
pan-left
.example {
touch-action: pan-left;
}
Permits panning that begins with a leftward gesture.
pan-right
.example {
touch-action: pan-right;
}
Permits panning that begins with a rightward gesture.
pan-up
.example {
touch-action: pan-up;
}
Permits panning that begins with an upward gesture.
pan-down
.example {
touch-action: pan-down;
}
Permits panning that begins with a downward gesture.
Combining Different Axes
.example {
touch-action: pan-left pan-up;
}
This permits gestures beginning in the specified horizontal or vertical directions.
Opposite Directions
The directional keywords are based on the gesture's initial direction. They do not necessarily restrict movement to that direction for the entire gesture.
Browser Compatibility
Directional panning values have less consistent support than pan-x and pan-y. Check compatibility before depending on them.
The pinch-zoom Value
The pinch-zoom value permits browser-managed pinch zooming using multiple touch points.
Basic Example
.zoom-area {
touch-action: pinch-zoom;
}
Allowing Vertical Panning
.zoom-area {
touch-action: pan-y pinch-zoom;
}
Allowing Horizontal Panning
.zoom-area {
touch-action: pan-x pinch-zoom;
}
Allowing Both Panning Axes
.zoom-area {
touch-action: pan-x pan-y pinch-zoom;
}
Important Distinction
The pinch-zoom keyword controls permission for browser-managed pinch zooming. It does not create a custom zoom interface or change an element's CSS transform value.
When to Use pinch-zoom
Use this keyword when browser zooming should remain available alongside selected panning gestures.
Combining Values
Compatible gesture keywords can be combined using spaces.
Horizontal Panning and Pinch Zooming
.example {
touch-action: pan-x pinch-zoom;
}
Vertical Panning and Pinch Zooming
.example {
touch-action: pan-y pinch-zoom;
}
Both Panning Axes
.example {
touch-action: pan-x pan-y;
}
Both Axes and Pinch Zooming
.example {
touch-action: pan-x pan-y pinch-zoom;
}
Directional Combination
.example {
touch-action: pan-right pan-down;
}
Invalid Comma Separation
.example {
touch-action: pan-x, pinch-zoom;
}
Use spaces rather than commas.
Invalid Keyword Combination
.example {
touch-action: none pan-y;
}
The none keyword cannot be combined with other gesture keywords.
Choosing a Combination
Allow the gestures necessary for the interface while avoiding restrictions that interfere with ordinary page scrolling or accessibility.
Touch Action and Pointer Events
The touch-action property is closely related to the Pointer Events API, which provides a common event model for mouse, pen, and touch input.
Custom Gesture Area
.gesture-area {
touch-action: none;
}
Listening for Pointer Events
const area = document.querySelector(".gesture-area");
area.addEventListener("pointerdown", (event) => {
console.log("Pointer started:", event.pointerId);
});
area.addEventListener("pointermove", (event) => {
console.log("Pointer moved:", event.clientX, event.clientY);
});
area.addEventListener("pointerup", (event) => {
console.log("Pointer ended:", event.pointerId);
});
The pointercancel Event
When the browser takes control of a gesture, such as scrolling, it may dispatch a pointercancel event to indicate that the application will no longer receive the expected pointer sequence.
area.addEventListener("pointercancel", () => {
console.log("Pointer interaction canceled");
});
Preventing Browser Gesture Conflicts
Setting an appropriate touch-action value before a gesture begins helps the browser determine which gestures belong to the page and which may be handled by application code.
Difference From pointer-events
| Property | Purpose |
|---|---|
touch-action |
Controls browser-managed touchscreen gestures. |
pointer-events |
Controls whether an element can be targeted by pointer events under applicable hit-testing rules. |
Important Consideration
The touch-action property does not implement dragging, drawing, or custom gestures by itself. JavaScript is needed to provide those interactions.
Related CSS Properties
Several CSS properties work with touch-action to control scrolling and interactive behavior.
pointer-events
.example {
pointer-events: auto;
}
Controls pointer-event hit testing.
overflow
.example {
overflow: auto;
}
Controls how content that exceeds an element's box is handled.
overflow-x
.example {
overflow-x: auto;
}
Controls horizontal overflow behavior.
overflow-y
.example {
overflow-y: auto;
}
Controls vertical overflow behavior.
overscroll-behavior
.example {
overscroll-behavior: contain;
}
Controls behavior when a scroll container reaches its scroll boundary, including scroll chaining.
scroll-behavior
.example {
scroll-behavior: smooth;
}
Controls the scrolling behavior for navigation or programmatic scrolling performed by the browser.
user-select
.example {
user-select: none;
}
Controls whether text can be selected.
Complete Example
.swipe-panel {
overflow-x: auto;
overscroll-behavior-x: contain;
touch-action: pan-x pinch-zoom;
}
This example allows horizontal touch panning and pinch zooming while containing horizontal overscroll behavior.
Inheritance
The touch-action property is not inherited. A child element does not automatically receive its parent's computed value.
Parent Element Example
.parent {
touch-action: pan-y;
}
Child Element
.child {
touch-action: auto;
}
The child retains its own auto value, but gestures beginning on it may still be restricted by the parent's pan-y declaration.
Explicit Inheritance
.child {
touch-action: inherit;
}
Restore the Initial Value
.child {
touch-action: initial;
}
This restores auto.
Using unset
.child {
touch-action: unset;
}
Because the property is not inherited, unset restores the initial value.
Important Distinction
Property inheritance and gesture permission are different concepts. The browser considers applicable ancestor restrictions even though the property itself is not inherited.
Practical Examples
Touch-Friendly Button
.touch-button {
padding: 12px 20px;
touch-action: manipulation;
}
Custom Drawing Canvas
.drawing-canvas {
display: block;
max-width: 100%;
touch-action: none;
}
Horizontal Scrolling Gallery
.gallery {
display: flex;
overflow-x: auto;
touch-action: pan-x pinch-zoom;
}
Vertical Scrolling Panel
.scroll-panel {
max-height: 300px;
overflow-y: auto;
touch-action: pan-y pinch-zoom;
}
Horizontal Swipe Cards
.swipe-card {
touch-action: pan-y pinch-zoom;
}
This preserves vertical page panning and pinch zooming while allowing JavaScript to implement horizontal swipe gestures.
Custom Drag Handle
.drag-handle {
cursor: grab;
touch-action: none;
}
Interactive Map With Custom Gestures
.custom-map {
touch-action: none;
}
Use this only when the application supplies appropriate custom gesture handling and accessible alternatives.
Allowing Standard Touch Behavior
.content-area {
touch-action: auto;
}
Directional Panning
.directional-area {
touch-action: pan-left pan-up;
}
Progressive Enhancement
@supports (touch-action: pan-y) {
.swipe-card {
touch-action: pan-y;
}
}
touch-action Example
This example compares the behavior of three scrollable areas using auto, pan-y, and none. On a touchscreen, try dragging vertically inside each area.
HTML Example
<div class="touch-demo">
<div class="touch-sample">
<strong>touch-action: auto;</strong>
<div class="touch-panel touch-auto">
<p>Item 1 - Scrollable content</p>
<p>Item 2 - Scrollable content</p>
<p>Item 3 - Scrollable content</p>
<p>Item 4 - Scrollable content</p>
</div>
</div>
<div class="touch-sample">
<strong>touch-action: pan-y;</strong>
<div class="touch-panel touch-pan-y">
<p>Item 1 - Scrollable content</p>
<p>Item 2 - Scrollable content</p>
<p>Item 3 - Scrollable content</p>
<p>Item 4 - Scrollable content</p>
</div>
</div>
<div class="touch-sample">
<strong>touch-action: none;</strong>
<div class="touch-panel touch-none">
<p>Item 1 - Scrollable content</p>
<p>Item 2 - Scrollable content</p>
<p>Item 3 - Scrollable content</p>
<p>Item 4 - Scrollable content</p>
</div>
</div>
</div>
CSS Example
.touch-demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
gap: 16px;
}
.touch-sample strong {
display: block;
margin-bottom: 8px;
}
.touch-panel {
height: 130px;
padding: 12px;
overflow-y: auto;
border: 1px solid #94a3b8;
background: #f8fafc;
}
.touch-panel p {
margin: 0 0 18px;
}
.touch-auto {
touch-action: auto;
}
.touch-pan-y {
touch-action: pan-y;
}
.touch-none {
touch-action: none;
}
Item 1 - Scrollable content
Item 2 - Scrollable content
Item 3 - Scrollable content
Item 4 - Scrollable content
Item 1 - Scrollable content
Item 2 - Scrollable content
Item 3 - Scrollable content
Item 4 - Scrollable content
Item 1 - Scrollable content
Item 2 - Scrollable content
Item 3 - Scrollable content
Item 4 - Scrollable content
Understanding the Results
The three panels contain the same scrollable content but use different touch-action values.
auto
The browser can handle normal touchscreen scrolling and supported zoom gestures.
pan-y
The browser can handle vertical touch panning but not horizontal panning or pinch zooming based on this declaration alone.
none
The browser does not handle normal touch panning or zooming gestures that begin on the panel. Other scrolling methods, such as a mouse wheel, scrollbar, or keyboard, may still work.
Testing on a Desktop Computer
A mouse wheel does not simulate touchscreen gesture permissions. Use an actual touchscreen or a browser's touch emulation tools to compare the behaviors.
Experiment With pinch-zoom
.touch-pan-y {
touch-action: pan-y pinch-zoom;
}
This permits both vertical panning and browser-managed pinch zooming.
Accessibility Considerations
Touch gestures are an important part of navigating websites, particularly for users who rely on zooming or alternative input methods.
Preserve Browser Zooming
Avoid disabling pinch zooming across large page regions. Users with low vision may rely on browser magnification to read and interact with content.
Avoid Global touch-action: none
body {
touch-action: none;
}
Applying this restriction broadly can interfere with scrolling and zooming. Use it only on small, dedicated custom gesture areas when necessary.
Provide Alternative Input Methods
Custom gestures should have accessible alternatives, such as buttons or keyboard controls, when they perform essential actions.
Keep Scrolling Available
Do not restrict vertical scrolling on content that users need to navigate unless another accessible scrolling method is provided.
Use manipulation Carefully
The manipulation value can improve touch interaction while preserving panning and pinch zooming.
Test Assistive Technology
Verify that custom gesture controls remain usable with screen readers, keyboard navigation, and alternative pointing devices.
Avoid Gesture-Only Functionality
Do not make important actions available only through swiping, dragging, or multi-touch gestures.
Use Appropriate Touch Targets
Interactive controls should have sufficient size and spacing to support accurate touch input.
Common Mistakes
Using touch-action to Create Scrolling
The property controls which browser gestures are allowed. It does not create overflow or make an element scrollable by itself.
Using Commas Between Values
.example {
touch-action: pan-x, pinch-zoom;
}
Compatible gesture keywords must be separated by spaces.
Combining auto With Other Keywords
.example {
touch-action: auto pan-y;
}
The auto keyword must be used alone.
Combining none With Other Keywords
.example {
touch-action: none pinch-zoom;
}
The none keyword cannot be combined with other values.
Using Invalid Keywords
.example {
touch-action: scroll;
}
Use one of the supported gesture keywords.
Expecting touch-action to Disable Pointer Events
The property does not prevent an element from receiving pointer events.
Confusing touch-action With pointer-events
These properties control different aspects of pointer interaction.
Changing touch-action During an Active Gesture
Changing the property after a gesture starts does not alter the browser's handling of that gesture.
Ignoring Ancestor Restrictions
Ancestor values can restrict the gestures available to a descendant even when the descendant uses auto.
Disabling Zoom Unnecessarily
Using none or restrictive panning values without pinch-zoom can interfere with browser zooming.
Expecting Custom Gestures Without JavaScript
The property does not implement custom dragging, swiping, or drawing behavior.
Testing Only With a Mouse
Mouse input does not fully represent touchscreen gesture behavior.
Assuming Directional Values Work Everywhere
Directional panning keywords may have different levels of browser support.
Restricting Entire Page Scrolling
Applying restrictive values to large containers can make navigation difficult on touch devices.
Important Considerations
Keep the following points in mind when using touch-action:
- The property controls browser-managed touchscreen gestures.
- The initial value is
auto. - The property is not inherited.
- Applicable ancestor values can restrict permitted gestures.
- The
nonevalue disables normal browser-managed panning and zooming gestures. - The
manipulationvalue permits panning and pinch zooming while disabling double-tap zooming. - The
pan-xvalue permits horizontal panning. - The
pan-yvalue permits vertical panning. - Directional keywords restrict the initial direction of panning.
- The
pinch-zoomvalue permits browser-managed pinch zooming. - Compatible values are separated by spaces.
- The keywords
auto,none, andmanipulationmust be used individually. - The property does not create scrolling or overflow.
- The property does not implement custom gestures.
- Pointer Events can be used to implement custom interactions.
- The browser determines allowed gestures when the gesture begins.
- Changing the property during an active gesture does not change that gesture's permissions.
- The property does not disable pointer event listeners.
- Mouse-wheel scrolling is not controlled in the same way as touchscreen panning.
- Restrictive values can interfere with browser zooming.
- Preserve accessible scrolling and magnification.
- Provide alternatives to custom gesture-only controls.
- Directional panning support varies between browsers.
- Test on actual touchscreen devices when possible.
- Use the least restrictive value that meets the interface's needs.
Browser Support
The CSS touch-action property is widely supported in modern browsers. Common values such as auto, none, manipulation, pan-x, and pan-y are broadly available, while directional panning values have more limited or inconsistent support.
For current compatibility information, visit Can I Use? and search for touch-action.
Basic Declaration
.example {
touch-action: manipulation;
}
Feature Detection
@supports (touch-action: pan-y) {
.swipe-area {
touch-action: pan-y;
}
}
Directional Value Detection
@supports (touch-action: pan-left) {
.directional-area {
touch-action: pan-left;
}
}
Testing Recommendations
Test gesture behavior on the browsers and devices your website supports. CSS feature detection checks whether a declaration is recognized but does not replace testing actual touch interactions.
Desktop Versus Touchscreen Behavior
Desktop browsers may support the property even when the current device has no touchscreen. Use touch input or browser touch emulation to evaluate its effects.
Specifications
The touch-action property is defined in the Pointer Events specification.
Pointer Events Level 3 - The touch-action CSS Property
The specification defines the permitted gesture keywords, how gesture permissions are determined, and how the property interacts with pointer events.
For additional documentation and examples, consult MDN Web Docs.
