waffl
waffl

Reputation: 5511

Meta viewport tag seems to be ignored completely or has no effect

I have put this tag in the head of a webpage:

<meta name="viewport" content="width=device-width,initial-scale=0.47,maximum-scale=1">

For some reason, it simply seems to be ignored on my iPhone, even adding user-scalable=no has no effect. I have tried many values of width, initial-scale etc... nothing seems to have any effect.

Does anyone know what might be causing this? I can see clearly in the source that it is there in the header.

My iPhone is on iOS7.

Edit: The problem is still happening on iOS6 with the xcode ios simulator, so I don't think it is due to iOS7.

Upvotes: 23

Views: 84944

Answers (7)

MalcolmOcean
MalcolmOcean

Reputation: 2985

While setting up og: and twitter: meta tags, I swapped out a bunch of my meta items to have a property attribute instead of a name attribute. Which works fine for those but does not work for viewport.

So I had this:

<meta property="viewport" content="width=device-width, initial-scale=1" />

...but needed this:

<meta name="viewport" content="width=device-width, initial-scale=1" />

Upvotes: 0

absqueued
absqueued

Reputation: 3063

Viewport width is different in many devices. iOS has 320, android has 360 in portrait mode. Landscape mode - it depends on which device you have, you will get a different pixel value.

The best way to make website optimized for mobile device is to set width=device-width. If you don't set initial-scale=1.0 - iOs will zoom in (enlarge) screen when changing device rotation.

This is the meta tag you need.

<meta name="viewport" content="width=device-width, initial-scale=1.0">

And if you wanted to disable the zoom feature, set user-scalable=no

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

Do not hard code width property as it will set same width for portrait and landscape modes - which is very unpleasing user experience.

Best documented: https://developer.apple.com/library/ios/documentation/AppleApplications/Reference/SafariWebContent/UsingtheViewport/UsingtheViewport.html

About iOs 7 Moreover I would say - dont worry about iOS7 as of now. It has so many bugs. Read here: http://www.sencha.com/blog/the-html5-scorecard-the-good-the-bad-and-the-ugly-in-ios7/

Upvotes: 8

ConduciveMammal
ConduciveMammal

Reputation: 483

I know this is a hella old question now but it was the first result in Google when I had this issue so thought I'd update in regards to iOS 10.

It seems Apple now completely overrides the user-scalable=no in iOS 10 in order to improve accessibility

See: Thomas Fuchs' Twitter Post

Upvotes: 11

WvdW
WvdW

Reputation: 141

You should try, as a workaround, the following code:

html { 
    zoom: .8; 
}

Upvotes: 14

Andreas Daoutis
Andreas Daoutis

Reputation: 1205

It is working! On your page you are using:

<meta content="width=640, initial-scale=0.47, maximum-scale=1.0, user-scalable=1" name="viewport">

When I open the page on my phone (ios7 iphone5) I see exactly the right result.

Are you 100% sure you really tried putting the following in your code?

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

It doesn't get ignored.

UPDATE1

I just saw that in your code it seems you are using my second viewport but i gets changed probably by javascript to the 640px viewport. Thats maybe the reason why for you it feels like it gets ignored. Because during runtime the viewport gets changed...

UPDATE2

Ok found the problem.

function updateWidth(){
    viewport = document.querySelector("meta[name=viewport]");
    if (window.orientation == 90 || window.orientation == -90) {
        viewport.setAttribute('content', 'width=1401, initial-scale=0.34, maximum-scale=1.0, user-scalable=1');
    }
    else {
        viewport.setAttribute('content', 'width=640, initial-scale=0.47, maximum-scale=1.0, user-scalable=1');
    }
} 

Your page is calling this function which overrides your viewport. Did you know about that function?

Upvotes: 48

sourav
sourav

Reputation: 676

It seems that ios7 is not recognising the meta tag properly. Here are the links which may help you.

webapp not scaling properly in iOS 7

http://www.mobilexweb.com/blog/safari-ios7-html5-problems-apis-review

Upvotes: 3

Fahim Parkar
Fahim Parkar

Reputation: 31627

Use below code.

<meta name="viewport" content="width=320, initial-scale=1, user-scalable=yes">

It works well in many of mine project.

Upvotes: -2

Related Questions