Skip to the content...

Welcome to the David Walsh Blog. I'm a MooTools, Dojo, jQuery, CSS, and PHP Web Developer located in Madison, Wisconsin, United States. Please contact me if I can make your experience on my website better.

Prevent Page Zooming in Mobile Browsers

4 Responses »

Ever since I got my iPhone, I've been more agreeable in going places that my fiancee wants to go. It's not because I have any interest in checking out women's shoes, looking at flowers, or that type of stuff -- it's because my iPhone lets me surf the web the whole time...or until my iPhone's tiny battery dies. It wasn't until recently that I noticed that some sites don't allow the user to zoom in and out of a page. After some research I found that preventing page zooming was as easy as adding a META tag to the page.

The META HTML Tag

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"/> <!--320-->

That's as easy as it gets. According to Mozilla, mobile browsers are generally set to a size of 320 or 480. The maximum scale keeps the scale settings when the user switches from portrait to landscape view.

If you'd like to see this in action, grab your phone/mobile browser and hit:

http://davidwalsh.name/zoom-mobile-browsers

I'm not huge fan of preventing the user from enhancing their experience but your web application may need to stay a given size. Now you know how to do so!

Discussion

  1. June 14, 2010 @ 9:45 am

    yeah this is well know technique, almost every mobile site is applying it! However if there’s no a mobile version it’s better to omit this tag.

  2. June 14, 2010 @ 11:54 am

    I personally, find it very annoying when I land a mobile version of a site while surfing on my iPhone. Often times I want to look more closely at photos on a page, and if the site set up to prevent zooming…I can’t see the images.

    I think from a usability standpoint, if we prevent zooming on the page in mobile devices, we have to provide a method for zooming the images.

  3. June 14, 2010 @ 4:32 pm

    I have been using this for building iPad based web apps (with Mootools of course :) ) where you want to be able to lock the screen down for when you want to include touch events ( http://tabqwerty.com/2010/04/08/supporting-mouse-events-in-mobile-safari.html )

    But I agree with eH? unless you have a good reason to lock the size, you shouldn’t!

  4. June 14, 2010 @ 6:43 pm

    @eH?, @Thomas: Agreed — don’t do it if you don’t *absolutely* need to.

Be Heard!

Share your thoughts with fellow developers of all skill levels! I want to hear from you!

Name*:
Email*:
Website:  
Wrap your code with <code> tags, f00!