97

I want to disable Pinch and Zoom on Mobile devices.

What configuration should I add to the viewport ?

Link : http://play.mink7.com/n/dawn/

Jezen Thomas
  • 13,619
  • 6
  • 53
  • 91
Harsha M V
  • 54,075
  • 125
  • 354
  • 529
  • initial-scale=1, maximum-scale=1 – SVS Jul 27 '12 at 14:04
  • 4
    Because you've disabled pinch zoom, making it mobile unfriendly – Steve Kuo Jun 13 '13 at 21:35
  • 17
    I hope you're not creating a website for a UK based organisation - if you are, disabling pinch-to-zoom (effectively an accessibility feature) would put you in breach of several laws for actively discriminating against people with visual impairments ... There is never a good reason to disable this functionality ... Ever! – Mike Insch Jul 09 '13 at 20:18
  • 27
    Not always a bad idea. If you are making an app like webpage thats what i would do. You cant always use app store so this is next best thing. – Shumii Jul 10 '13 at 22:28
  • 13
    Please stop doing this. The visually impaired can't view websites without zooming in on them and this makes our lives much harder. – Jack Marchetti Nov 21 '13 at 02:13
  • 6
    I fail to see how disabling pinchzoom on an "app-like" webpage adds any value. All you're going to do is anger your users. – Steve Kuo Dec 25 '13 at 18:48
  • 3
    Disabling zoom on mobile is always a bad idea, except when you want/have to use elements with fixed position. Only in this last case, you **need** to disable pinch to zoom or your site/app will appear screwed up, buggy and unusable as soon as the user zoom in. – guari Oct 23 '14 at 17:47
  • Do visually impaired people have difficulty using apps that don't have pinch/zoom, or is there some other mechanism that helps with using such apps? – James Oct 30 '14 at 22:15
  • @JamesFoster app font can be set a system level under "Accessibility" or "Display", or per app basis (the most serious ones). – Paranoid Android Nov 25 '14 at 15:08
  • 55
    Could you imagine making a "Google Maps" style app, and the first time you pinch to zoom in, you can no longer see the TEXT ENTRY BOX? Or the COPYRIGHT SYMBOLS? Sometimes, you don't want the ENTIRE APP to zoom. Sometimes, you just want PART OF IT to zoom. – Ayelis Apr 23 '15 at 21:07
  • 2
    @MikeInsch Time for the UK to sue GOOGLE. – Ayelis Apr 23 '15 at 21:12
  • 13
    if you are designing a responsive single page web application, the pinch zoom (also automatic zoom) really disturbs the workflow, because the browser automatically zoom in if you accidentally double click on an empty space. – Tower Jimmy Jun 07 '15 at 08:18
  • 1
    On my case, I was using the map.net API, and the library failed because they have their own zoom handle, so I was forced to disable the pinch feature on the browser in order to have the correct behavior. – BernieSF Sep 10 '15 at 18:19
  • EVIL!!!!!!!!!!! Don’t be. – Aditya M P May 29 '19 at 14:10
  • Does this answer your question? [How can I "disable" zoom on a mobile web page?](https://stackoverflow.com/questions/4472891/how-can-i-disable-zoom-on-a-mobile-web-page) – Shahar 'Dawn' Or Jun 25 '20 at 07:39
  • 1
    Disabling pinch zoom on mobile devices is one of the worse things developers had invented. DON'T DO IT! – icefront Jan 23 '21 at 16:55
  • 2
    From 11years professional experience in the field, I've found many valid reasons to prevent zoom. I dont understand this debate. – Chris GW Green Jun 30 '22 at 11:40
  • Stop judging people who want to use this. I wrote a learning webapp for my kids, with swipe cards. They keep to zoom unwillingly, so I need to disable that feature. That's a perfectly legitimate usecase, and I wager not the only one. – Boiethios Dec 12 '22 at 16:56

12 Answers12

202

EDIT: Because this keeps getting commented on, we all know that we shouldn't do this. The question was how do I do it, not should I do it.

Add this into your for mobile devices. Then do your widths in percentages and you'll be fine:

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />

Add this in for devices that can't use viewport too:

<meta name="HandheldFriendly" content="true" />
SpaceBeers
  • 13,617
  • 6
  • 47
  • 61
  • 43
    i have added that. but still i am able to pinch and zoom. – Harsha M V Jul 27 '12 at 14:12
  • thanks i had a default port value. so it was being over ridden – Harsha M V Jul 27 '12 at 14:14
  • Ah ok. I was going to say it's fine on my phone. – SpaceBeers Jul 27 '12 at 14:15
  • 1
    What is the difference between this and http://stackoverflow.com/a/4472910/198348 ? – Ehtesh Choudhury Aug 31 '13 at 08:44
  • 3
    @Shurane They're different questions? – SpaceBeers Aug 31 '13 at 11:54
  • 1
    Why on earth would you do this? – Karlth Dec 12 '14 at 11:17
  • 1
    @user357320 - The question isn't should we disable pinch zoom on mobile web. We all agree it's a usability faux pas. – SpaceBeers Dec 12 '14 at 11:20
  • 1
    @SpaceBeers - Unless you're programming a web-app that already has pinch-zoom functionality. Then you'd lose your interface the first time you zoomed. Usability, gone! – Ayelis Apr 23 '15 at 21:23
  • @Ayelis - Yes, we all know this. I've made an edit to the answer so I don't have to keep saying it. – SpaceBeers Apr 27 '15 at 13:41
  • @Karlth to avoid a user zooming to a position where their experience suffers. Have you ever accidentally zoomed on a web page? I'm sure you have. We all have. – Michael Oct 08 '15 at 14:48
  • @MikeMilla I've also accidentally dropped my phone but that doesn't mean I want it covered in foam! – Karlth Oct 08 '15 at 16:27
  • @Karlth haha! But if I could ensure you (without foam) that when you picked the phone up off the floor it would be in the exact same condition as when it left your hands, I'm sure you'd take me up on that. – Michael Oct 08 '15 at 17:03
  • @Karlth When you pick up your phone from the ground, even if it's still in one piece, think about your confusion when you discover that you've accidentally zoomed in while holding it by the screen... :) – Stan Oct 23 '15 at 13:43
  • @Karlth if your application provides its own zooming idioms (e.g. 3d navigation) – SapphireSun Oct 10 '16 at 19:29
  • 22
    2019: PWA's are a thing now and this is a solution to prevent PWA's having strange behaviors on mobile devices :) – Jessy Jan 25 '19 at 00:56
  • It is nice seeing these answers evolve with the web. – SpaceBeers Jan 25 '19 at 11:09
  • Note that Chrome on Android has a setting under Settings > Accessibility to "Force Enable Zoom". That needs to be unchecked for this and other solutions to work. It was checked by default on my Samsung M51. Other browsers may have similar settings. – Nick Hope Jan 12 '22 at 15:55
  • @Jessy one of the big benefits of a PWA over a native app is automatic handling of UX features such as zoom. If you don't want zoom (or all the other nice features a browser provides for free, such as copy-pasting text, saving, printing, aggressive power management, etc.), consider developing a native app. There are cross-platform frameworks such as Unity for making videogames (99.9% of apps where you wouldn't want pinch-to-zoom are videogames). – hegel5000 Aug 07 '23 at 22:34
18

this will prevent any zoom action by the user in ios safari and also prevent the "zoom to tabs" feature:

document.addEventListener('gesturestart', function(e) {
    e.preventDefault();
    // special hack to prevent zoom-to-tabs gesture in safari
    document.body.style.zoom = 0.99;
});

document.addEventListener('gesturechange', function(e) {
    e.preventDefault();
    // special hack to prevent zoom-to-tabs gesture in safari
    document.body.style.zoom = 0.99;
});

document.addEventListener('gestureend', function(e) {
    e.preventDefault();
    // special hack to prevent zoom-to-tabs gesture in safari
    document.body.style.zoom = 0.99;
});

jsfiddle: https://jsfiddle.net/vo0aqj4y/11/

trias
  • 635
  • 7
  • 10
15

This is all I needed:

<meta name="viewport" content="user-scalable=no"/>
quemeful
  • 9,542
  • 4
  • 60
  • 69
13

I think what you may be after is the CSS property touch-action. You just need a CSS rule like this:

html, body {touch-action: none;}

You will see it has pretty good support (https://caniuse.com/#feat=mdn-css_properties_touch-action_none), including Safari, as well as back to IE10.

Mr Incredible
  • 441
  • 4
  • 8
11

To everyone who said that this is a bad idea I want to say it is not always a bad one. Sometimes it is very boring to have to zoom out to see all the content. For example when you type on an input on iOS it zooms to get it in the center of the screen. You have to zoom out after that cause closing the keyboard does not do the work. Also I agree that when you put many I hours in making a great layout and user experience you don't want it to be messed up by a zoom.

But the other argument is valuable as well for people with vision issues. However In my opinion if you have issues with your eyes you are already using the zooming features of the system so there is no need to disturb the content.

Thibaut Rey
  • 318
  • 2
  • 5
  • 5
    You should make this as a comment. – Awesomeness01 May 20 '15 at 02:27
  • 3
    Sorry, my level at the time didn't allow me to post comments but only new message, that's why. – Thibaut Rey May 25 '15 at 09:32
  • 2
    Setting font-size to 16px on form elements will prevent a zoom on iOS devices. – hellojebus May 26 '15 at 04:14
  • 1
    I can tell that you are not in your 50s. For many of us, it's not that we have vision issues serious enough such that we have to use special accommodations (even reading glasses), EXCEPT when using web pages on our iPads that designers think are perfect with their tiny fonts. Such pages tell me "I don't care whether you can read this or not, old man." – fool4jesus Jul 09 '16 at 14:03
  • 4
    i'm an older man with eyesight issues, and yet I totally get why it's needed sometimes. "websites" are not always intended for use by the general public or for every single member of society, in the same way that it would be insane to force every citizen to install wheelchair ramps and unisex toilet blocks in their houses, because "that's the law you know". sure if you are providing public access, or employing people, then those consideration come into play in architecture. there are for example single page web app games that would be ruined by allowing people to zoom in and out. – unsynchronized Sep 04 '16 at 04:17
  • @unsynchronized even if you don't care about being able to read a web page with your eyes, the reality is that people who do care vastly outnumber people who want to use a mobile web app where disabling zoom actually is necessary. It is insane to force everybody not to use pinch to zoom just to cater to the handful of cases where it actually needs to be disabled. – hegel5000 Aug 08 '23 at 16:47
  • To clarify, what I mean is that ending the option to disable pinch-to-zoom is a much more rational appeal to the majority. It would adversely affect far fewer people and benefit far more than what we have now where disabling pinch to zoom is thrown around willy nilly. – hegel5000 Aug 08 '23 at 17:00
9

Unfortunately, the offered solution doesn't work in Safari 10+, since Apple has decided to ignore user-scalable=no. This thread has more details and some JS hacks: disable viewport zooming iOS 10+ safari?

s-f
  • 2,091
  • 22
  • 28
6

Found here you can use user-scalable=no:

<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
AymDev
  • 6,626
  • 4
  • 29
  • 52
some one
  • 61
  • 1
  • 1
4

IE has its own way: A css property, -ms-content-zooming. Setting it to none on the body or something should disable it.

Disable pinch to zoom in IE10

http://msdn.microsoft.com/en-us/library/ie/hh771891(v=vs.85).aspx

Community
  • 1
  • 1
nafg
  • 2,424
  • 27
  • 25
4

For anyone still needing this feature, none of the other answers work in newer versions of the iOS. You only need to add this CSS code to the CSS Inline section of your Apex page:

@media screen and (-webkit-min-device-pixel-ratio: 0) {

.apex-item-select:focus, .apex-item-text:focus, .apex-item-textarea:focus {

        font-size: 16px;

    }

    .apex-item-select, .apex-item-text, .apex-item-textarea {

        font-size: 16px;

    }

}

It completely fixes the auto-zoom-in problem in the iOS devices.

iminiki
  • 2,549
  • 12
  • 35
  • 45
3

Disables iOS pinch-zoom

window.addEventListener(
  "touchmove",
  function (event) {
    if (event.scale !== 1) {
      event.preventDefault();
      event.stopImmediatePropagation();
    }
  },
  { passive: false }
);

Tested on iOS 15.3 in Safari and Brave.

Reggie Pinkham
  • 11,985
  • 4
  • 38
  • 36
0

Try with min-width property. Let me explain you. Assume a device with screen width of 400px (for an instance). When you zoom in, the fonts gets larger and larger. But boxes and divs remains with same width. If you use min-width, you can avoid decreasing your div and box.

Ajay Sharma
  • 108
  • 1
  • 3
0

Not sure is this could help, but I solved the pinch / zoom problem (I wanted to avoid users to do zooming on my webapp) using angular hammer module:

In my app.component.html I added:

<div id="app" (pinchin)="pinchin();">

and in my app.component.ts:

  pinchin() {
      //console.log('pinch in');
  }