{"id":280309,"date":"2019-01-02T08:18:55","date_gmt":"2019-01-02T15:18:55","guid":{"rendered":"http:\/\/css-tricks.com\/?page_id=280309"},"modified":"2019-01-02T08:18:55","modified_gmt":"2019-01-02T15:18:55","slug":"touch-action","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/almanac\/properties\/t\/touch-action\/","title":{"rendered":"touch-action"},"content":{"rendered":"
The The <\/p>\n The most obvious example of this is an interactive map element. If you’ve ever viewed a map not designed to work with touch devices, you’ve probably tried to pinch and zoom only to find the browser magnifying the element, but not actually zooming the actual map.<\/p>\n By default, a browser will handle touch interactions automatically: Pinch to zoom, swipe to scroll, etc. Setting See the Pen examples of touch-action<\/a> by CSS-Tricks (@css-tricks<\/a>) on CodePen<\/a>.<\/p>\n The This browser support data is from Caniuse<\/a>, which has more detail. A number indicates that browser supports the feature at that version and up.<\/p><\/div>touch-action<\/code> property in CSS gives you control over the effect of touchscreen interactions with an element, similar to the more widely-used
pointer-events<\/a><\/code> property used to control mouse interactions.<\/p>\n
#element {\r\n touch-action: pan-right pinch-zoom;\r\n}<\/code><\/pre>\n
touch-action<\/code> property is useful primarily for interactive UI elements that need slightly different behavior depending on the type of device being used. When your users might expect an element to behave a particular way with a mouse, and slightly different behavior on a touch screen,
touch-action<\/code> will come in handy.<\/p>\n
touch-action<\/code> to
none<\/code> will disable all browser handling of these events, leaving them up to you to implement (via JavaScript). If you only want to take over one interaction, tell the browser to handle the rest. For example, if you wrote some JavaScript that only handles zooming, you can tell the browser to handle everything else with this property:
touch-action: pan-x pan-y;<\/code>.<\/p>\n
Syntax<\/h3>\n
touch-action: auto | none | [ [ pan-x | pan-left | pan-right ] || [ pan-y | pan-up | pan-down ] || pinch-zoom ] | manipulation<\/code><\/pre>\n
Values<\/h3>\n
touch-action<\/code> property accepts the following values:<\/p>\n
\n
auto<\/code>: Allows the browser to handle all pan and zoom interactions.<\/li>\n
none<\/code>: Disables browsers from handling all pan and zoom interactions. This opens up the ability to custom define those interactions in JavaScript.<\/li>\n
pan-x<\/code>: Enables horizontal panning with a single finger interaction. It is shorthand for the
pan-left<\/code> and
pan-right<\/code> values, but can be used in combination with
pan-y<\/code>,
pan-up<\/code>,
pan-down<\/code> and
pinch-zoom<\/code>.<\/li>\n
pan-y<\/code> Enables vertical panning with a single finger interaction. It is shorthand for the
pan-up<\/code> and
pan-down<\/code> values, but can be used in combination with
pan-x<\/code>,
pan-left<\/code>,
pan-right<\/code> and
pinch-zoom<\/code>.<\/li>\n
manipulation<\/code>: Enables pinch and zoom interactions, but disables others you might find on some devices, like double-tap to zoom. It is shorthand for the combination of
pan-x pan-y pinch-zoom<\/code>.<\/li>\n
pan-left<\/code> (Experimental): Enables a single finger interaction when a user’s finger moves to the right, which pans toward the left.<\/li>\n
pan-right<\/code> (Experimental): Enables a single finger interaction when a user’s finger moves to the left, which pans toward the right.<\/li>\n
pan-down<\/code> (Experimental): Enables a single finger interaction when a user’s finger moves up, which pans downward.<\/li>\n
pan-up<\/code> (Experimental): Enables a single finger interaction when a user’s finger moves down, which pans upward.<\/li>\n
pinch-zoom<\/code>: Enables multi-finger interactions and can be combined with any other
pan-<\/code> value.<\/li>\n<\/ul>\n
Related<\/h3>\n
\n
pointer-events<\/code><\/a><\/li>\n<\/ul>\n
Browser Support<\/h3>\n
Desktop<\/h4>