Open the Settings app on the iPhone or iPad. Scroll down and choose the Safari browser from Settings. From Safari Settings, select the Page Zoom Safari option. Within the window, tap to select the Zooming level.
In the viewport meta tag above:maximum-scale=1 fixes the maximum scale of the page to 1.0. This prevents Safari from auto-zooming while still allowing the user to zoom in manually.
To disable pinch-zoom in HTML, simply add <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> to the <head> section.
If you enlarge the field by increasing all dimensions by 16 / 12 = 133.33%, then reduce using scale() by 12 / 16 = 75%, the input field will have the correct visual size (and font size), and there will be no zoom on focus.
It's possible to prevent webpage scaling in safari on iOS 10, but it's going to involve more work on your part. I guess the argument is that a degree of difficulty should stop cargo-cult devs from dropping "user-scalable=no" into every viewport tag and making things needlessly difficult for vision-impaired users.
Still, I would like to see Apple change their implementation so that there is a simple (meta-tag) way to disable double-tap-to-zoom. Most of the difficulties relate to that interaction.
You can stop pinch-to-zoom with something like this:
document.addEventListener('touchmove', function (event) {
if (event.scale !== 1) { event.preventDefault(); }
}, false);
Note that if any deeper targets call stopPropagation on the event, the event will not reach the document and the scaling behavior will not be prevented by this listener.
Disabling double-tap-to-zoom is similar. You disable any tap on the document occurring within 300 milliseconds of the prior tap:
var lastTouchEnd = 0;
document.addEventListener('touchend', function (event) {
var now = (new Date()).getTime();
if (now - lastTouchEnd <= 300) {
event.preventDefault();
}
lastTouchEnd = now;
}, false);
If you don't set up your form elements right, focusing on an input will auto-zoom, and since you have mostly disabled manual zoom, it will now be almost impossible to unzoom. Make sure the input font size is >= 16px.
If you're trying to solve this in a WKWebView in a native app, the solution given above is viable, but this is a better solution: https://stackoverflow.com/a/31943976/661418. And as mentioned in other answers, in iOS 10 beta 6, Apple has now provided a flag to honor the meta tag.
Update May 2017: I replaced the old 'check touches length on touchstart' method of disabling pinch-zoom with a simpler 'check event.scale on touchmove' approach. Should be more reliable for everyone.
This is a new feature in iOS 10.
From the iOS 10 beta 1 release notes:
- To improve accessibility on websites in Safari, users can now pinch-to-zoom even when a website sets
user-scalable=no
in the viewport.
I expect we're going to see a JS add-on soon to disable this in some way.
I've been able to fix this using the touch-action
css property on individual elements. Try setting touch-action: manipulation;
on elements that are commonly clicked on, like links or buttons.
The workaround that works in Mobile Safari at this time of writing, is to have the the third argument in addEventListener
be { passive: false }
, so the full workaround looks like this:
document.addEventListener('touchmove', function (event) {
if (event.scale !== 1) { event.preventDefault(); }
}, { passive: false });
You may want to check if options are supported to remain backwards compatible.
It appears that this behavior is supposedly changed in the latest beta, which at the time of writing is beta 6.
From the release notes for iOS 10 Beta 6:
WKWebView
now defaults to respectinguser-scalable=no
from a viewport. Clients ofWKWebView
can improve accessibility and allow users to pinch-to-zoom on all pages by setting theWKWebViewConfiguration
propertyignoresViewportScaleLimits
toYES
.
However, in my (very limited) testing, I can't yet confirm this to be the case.
Edit: verified, iOS 10 Beta 6 respects user-scalable=no
by default for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With