Disabling Viewport Zoom on iOS 14 Web Browsers

I recently answered a question on Discord on how to disable double-tap to zoom on iOS browsers. I looked this problem up on Google, and most people said to use the viewport meta tag. Except that was four years ago and it seems that Safari no longer res…


This content originally appeared on DEV Community and was authored by jasperreddin

I recently answered a question on Discord on how to disable double-tap to zoom on iOS browsers. I looked this problem up on Google, and most people said to use the viewport meta tag. Except that was four years ago and it seems that Safari no longer respects those tags.

Many are using Javascript to solve this, but that could be unreliable in many ways.

But now, since Safari 13, there is a way to disable viewport zooming.

body {
  touch-action: pan-y;
}

What the touch-action property does is it disables all touch events going to the selected element(s) except for the value specified. So by setting the property to pan-y for the whole body, we're only letting the user pan up and down, no matter where they initiate the touch. Any other touch events, whether it be a double tap, a pinch, or even a pan left or right, will be ignored.

You can read more about the touch-action CSS property here

If you need to allow the user to pan both up or down and left or right, you can add pan-x:

body {
  touch-action: pan-y, pan-x;
}

If you have just pan-y turned on in your body selector, and you have smaller viewports inside your document where there will be horizontal scrolling, you can override the property value in the child element.

.childViewPortElement {
  overflow: scroll;
   ...
  touch-action: pan-y, pan-x;
}

Fair Warning

In my testing I found out that on iOS, viewport zoom is fully disabled when the touch-action property is restricted like this. This applies even to automatic zooms that the browser performs, such as when the user taps on a text box with a font size smaller than 16px.

However, if even one element in the body has touch-action set to pinch-zoom or manipulation the browser will perform automatic zooms when tapping on small text boxes.

So be mindful of that, if you do have to enable manipulation or pinch-zoom events.


This content originally appeared on DEV Community and was authored by jasperreddin


Print Share Comment Cite Upload Translate Updates
APA

jasperreddin | Sciencx (2021-04-11T20:13:52+00:00) Disabling Viewport Zoom on iOS 14 Web Browsers. Retrieved from https://www.scien.cx/2021/04/11/disabling-viewport-zoom-on-ios-14-web-browsers/

MLA
" » Disabling Viewport Zoom on iOS 14 Web Browsers." jasperreddin | Sciencx - Sunday April 11, 2021, https://www.scien.cx/2021/04/11/disabling-viewport-zoom-on-ios-14-web-browsers/
HARVARD
jasperreddin | Sciencx Sunday April 11, 2021 » Disabling Viewport Zoom on iOS 14 Web Browsers., viewed ,<https://www.scien.cx/2021/04/11/disabling-viewport-zoom-on-ios-14-web-browsers/>
VANCOUVER
jasperreddin | Sciencx - » Disabling Viewport Zoom on iOS 14 Web Browsers. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/04/11/disabling-viewport-zoom-on-ios-14-web-browsers/
CHICAGO
" » Disabling Viewport Zoom on iOS 14 Web Browsers." jasperreddin | Sciencx - Accessed . https://www.scien.cx/2021/04/11/disabling-viewport-zoom-on-ios-14-web-browsers/
IEEE
" » Disabling Viewport Zoom on iOS 14 Web Browsers." jasperreddin | Sciencx [Online]. Available: https://www.scien.cx/2021/04/11/disabling-viewport-zoom-on-ios-14-web-browsers/. [Accessed: ]
rf:citation
» Disabling Viewport Zoom on iOS 14 Web Browsers | jasperreddin | Sciencx | https://www.scien.cx/2021/04/11/disabling-viewport-zoom-on-ios-14-web-browsers/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.