Related files:
Last major update on 17 February 2011.
Here’s the inevitable compatibility table that goes with my viewport research. It treats the viewports themselves as well as some related items.
See A tale of two viewports for a further explanation of these terms.
width: 20% are calculated relative to this viewport. Is usually quite a bit
wider than the visual viewport.This table looks into the properties that are necessary to read out useful information about the two viewports. As you can see, some of them are a mess and others are very well supported.
| Property | Opera Mobile | Opera Mini | iPhone | Android | Symbian | S40 | Dolfin | Black |
Palm | Phantom | Obigo | Bolt | Firefox | MicroB | IE Mobile | Black |
Net |
Obigo | UCWeb | |||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Presto | WebKit | Gecko | ||||||||||||||||||||||
|
screen.width and screen.height
Screen resolution in device pixels. Should change when the orientation of the device is changed. |
Almost | Yes | Incom |
Yes | HTML or layout | Yes | Incom |
Layout | Yes | Don’t know | Yes | Yes | Incom |
Incor |
||||||||||
|
Note that this resolution is almost completely useless to web developers. If it’s too small, people will want to zoom in anyway. <html> element in CSS pixels.
I test Opera Mobile, IE, and NetFront on the same Windows Mobile device. The Opera and NetFront problems are thus not device-related: IE gets it right on the same device. |
||||||||||||||||||||||||
|
window.innerWidth and window.innerHeight
Dimensions of the visual viewport in CSS pixels. |
screen | Yes | layout | Yes | HTML or layout | Yes | layout | Yes | layout | screen | layout | No | v 4.7 | layout | Don’t know | Incor |
||||||||
<html> element in CSS pixels.
|
||||||||||||||||||||||||
| Property | Opera Mobile | Opera Mini | iPhone | Android | Symbian | S40 | Dolfin | Black |
Palm | Phantom | Obigo | Bolt | Firefox | MicroB | IE Mobile | Black |
Net |
Obigo | UCWeb | |||||
| Presto | WebKit | Gecko | ||||||||||||||||||||||
|
documentElement. offsetWidth and documentElement. offsetHeight
Dimensions of the |
Yes | Yes | Yes | visual | Yes | Incor |
Yes | Incor |
||||||||||||||||
|
The dimensions of the HTML element are still important because they’re sometimes used for other purposes, such as media queries.
|
||||||||||||||||||||||||
|
documentElement. clientWidth and documentElement. clientHeight
Dimensions of the layout viewport in CSS pixels. |
Yes | Yes | Visual | HTML or Yes | Yes | HTML | Yes | Yes | Incor |
No | Incor |
Yes | Incor |
|||||||||||
<html> element in CSS pixels.
|
||||||||||||||||||||||||
|
pageXOffset and pageYOffset
Scrolling offset of the page in CSS pixels. |
0 | Yes | Depends | Yes | 0 | Depends | Yes | 0 | 0 | Yes | No | 0 | Yes | 0 | ||||||||||
|
||||||||||||||||||||||||
|
documentElement. scrollLeft and documentElement. scrollTop
Scrolling offset of the page in CSS pixels. |
0 | 0 | 0 | Yes | Yes | No | 0 | Yes | 0 | |||||||||||||||
|
In practice you need these properties only for IE — just as on desktop. |
||||||||||||||||||||||||
| Property | Opera Mobile | Opera Mini | iPhone | Android | Symbian | S40 | Dolfin | Black |
Palm | Phantom | Obigo | Bolt | Firefox | MicroB | IE Mobile | Black |
Net |
Obigo | UCWeb | |||||
| Presto | WebKit | Gecko | ||||||||||||||||||||||
Before we proceed, a caution. There is no official standard for any of this; I call a behaviour that makes sense and is supported by more browsers than any competing behaviour the “standard.” Any standard is better than no standard.
Besides, it’s not exactly easy right now to write cross-browser scripts because many properties give false information.
Let’s take the dimensions of the visual viewport as an example. This is by far the most important information because it tells us how much stuff the user actually sees.
Six browsers store the information in window.innerWidth/ Height. IE stores it in another property
pair. The other twelve browsers just don’t give this information anywhere.
Worse, when you query window.innerWidth/ Height
these twelve browser return the dimensions not of the visual viewport, but of the screen or
the layout viewport — or pure gibberish.
That makes window.innerWidth/ Height rather hard to use at the moment. Even worse, we
can’t find out whether window.innerWidth/ Height works or not;
there is no useful JavaScript check we can do to validate the values a browser returns.
I kind of assume the other browser vendors will implement window.innerWidth/ Height as
Apple, Nokia, and RIM did. We web developers badly need the data.
With that caveat in mind, how does the previous table translate to getting the actual data you need? The table below details that.
| Property | Opera Mobile | Opera Mini | iPhone | Android | Symbian | S40 | Dolfin | Black |
Palm | Phantom | Obigo | Bolt | Firefox | MicroB | IE Mobile | Black |
Net |
Obigo | UCWeb | |||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Presto | WebKit | Gecko | ||||||||||||||||||||||
|
Screen size
In device pixels. Useless in practice. |
Almost | Yes | Incom |
Yes | No | Yes | Incom |
No | Yes | No | Yes | Yes | Incom |
No | ||||||||||
|
Should be
I test Opera Mobile, IE, and NetFront on the same Windows Mobile device. The Opera and NetFront problems are thus not device-related: IE gets it right on the same device. |
||||||||||||||||||||||||
|
Visual viewport size
In CSS pixels. |
No | Yes | No | Yes | No | Yes | No | Yes | No | No | Alter |
Yes | No | |||||||||||
|
Should be
|
||||||||||||||||||||||||
| Property | Opera Mobile | Opera Mini | iPhone | Android | Symbian | S40 | Dolfin | Black |
Palm | Phantom | Obigo | Bolt | Firefox | MicroB | IE Mobile | Black |
Net |
Obigo | UCWeb | |||||
| Presto | WebKit | Gecko | ||||||||||||||||||||||
|
Layout viewport size
In CSS pixels. |
Yes | Yes | No | Depends | Yes | No | Yes | No | Yes | No | Incor |
No | ||||||||||||
|
Should be
Note: Some browsers (S40, Obigo WebKit) make the layout viewport and the
|
||||||||||||||||||||||||
|
HTML element size
Actual size of the HTML element. In CSS pixels |
yes | yes | yes | Alter |
yes | Incor |
yes | No | ||||||||||||||||
|
Should be
|
||||||||||||||||||||||||
|
Offset of visual viewport
The scrolling offset of the visual viewport relative to the layout viewport |
No | Yes | Depends | Yes | No | Depends | Yes | No | Yes | Alter |
No | Yes | No | |||||||||||
|
Should be
|
||||||||||||||||||||||||
| Property | Opera Mobile | Opera Mini | iPhone | Android | Symbian | S40 | Dolfin | Black |
Palm | Phantom | Obigo | Bolt | Firefox | MicroB | IE Mobile | Black |
Net |
Obigo | UCWeb | |||||
| Presto | WebKit | Gecko | ||||||||||||||||||||||
I left out the proxy browsers (Opera Mini, Bolt, UCWeb) because their lack of client-side interactivity makes reading out event coordinates pointless (not to mention very hard).
| Property | Opera Mobile | iPhone | Android | Symbian | S40 | Dolfin | Black |
Palm | Phantom | Obigo | Firefox | MicroB | IE Mobile | Black |
Net |
Obigo | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Presto | WebKit | Gecko | ||||||||||||||||||||||
|
clientX/Y
In CSS pixels, relative to the visual viewport |
Incor |
page | Yes | page | Yes | page | Yes | page | Yes | screen | page | screen | ||||||||||||
|
||||||||||||||||||||||||
|
pageX/Y
In CSS pixels, relative to the layout viewport |
10.1b | Yes | Yes | No | screen | No | ||||||||||||||||||
|
||||||||||||||||||||||||
|
screenX/Y
In device pixels, relative to the visual viewport |
Incor |
Yes | client | Yes | page | Yes | page | client | Yes | |||||||||||||||
|
||||||||||||||||||||||||
| Property | Opera Mobile | iPhone | Android | Symbian | S40 | Dolfin | Black |
Palm | Phantom | Obigo | Firefox | MicroB | IE Mobile | Black |
Net |
Obigo | ||||||||
| Presto | WebKit | Gecko | ||||||||||||||||||||||
Opera Widget Manager: all three correct. Since there is no zoom, client is always equal to screen.
Note: here I test whether the browser takes its width and height information from the correct source. Even if the source properties report wrong information, the media query support is still judged correct if it copies its information from the right properties.
| Property | Opera Mobile | Opera Mini | iPhone | Android | Symbian | S40 | Dolfin | Black |
Palm | Phantom | Obigo | Bolt | Firefox | MicroB | IE Mobile | Black |
Net |
Obigo | UCWeb | |||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Presto | WebKit | Gecko | ||||||||||||||||||||||
|
device width/height
Uses |
Yes | Yes | Static | Yes | Yes | No | ||||||||||||||||||
@media all and (max-device-width: 400px) {
// styles assigned when device width is smaller than 400px;
}
|
||||||||||||||||||||||||
|
width/height
Uses |
Yes | Yes | Static | Yes | Almost | Yes | Yes | No | ||||||||||||||||
@media all and (max-width: 400px) {
// styles assigned when width is smaller than 400px;
}
Opera Mini: since innerWidth, clientWidth, and screen.width are the same, the two media queries will yield the same result.
|
||||||||||||||||||||||||
| Property | Opera Mobile | Opera Mini | iPhone | Android | Symbian | S40 | Dolfin | Black |
Palm | Phantom | Obigo | Bolt | Firefox | MicroB | IE Mobile | Black |
Net |
Obigo | UCWeb | |||||
| Presto | WebKit | Gecko | ||||||||||||||||||||||
| Property | Opera Mobile | Opera Mini | iPhone | Android | Symbian | S40 | Dolfin | Black |
Palm | Phantom | Obigo | Bolt | Firefox | MicroB | IE Mobile | Black |
Net |
Obigo | UCWeb | |||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Presto | WebKit | Gecko | ||||||||||||||||||||||
|
Basics
Sets the dimensions of the layout viewport. |
Yes | No | Yes | No | Yes | Buggy | Yes | No | Yes | No | Yes | No | Yes | No | ||||||||||
<meta name="viewport" content="width = 380"> <meta name="viewport" content="width = device-width"> Should narrow the layout viewport to the indicated width. The
General Dolfin note: when a |
||||||||||||||||||||||||
|
Change immediately
Change the tag directly after it’s been written into the page Test page |
Yes | n/a | Yes | n/a | Yes | n/a | To be tested | n/a | No | n/a | Yes | To be tested | n/a | Yes | n/a | |||||||||
<meta id="testViewport" name="viewport" content="width = 380">
<script>
var mvp = document.getElementById('testViewport');
mvp.setAttribute('content','width=480');
</script>
|
||||||||||||||||||||||||
|
Change later
Change the tag once the page has been loaded Test page |
No | n/a | Yes | n/a | No | Yes | n/a | To be tested | n/a | No | n/a | No | To be tested | n/a | No | n/a | ||||||||
<meta id="testViewport" name="viewport" content="width = 380">
<script>
window.onload = function () {
var mvp = document.getElementById('testViewport');
mvp.setAttribute('content','width=580');
}
</script>
|
||||||||||||||||||||||||
| Property | Opera Mobile | Opera Mini | iPhone | Android | Symbian | S40 | Dolfin | Black |
Palm | Phantom | Obigo | Bolt | Firefox | MicroB | IE Mobile | Black |
Net |
Obigo | UCWeb | |||||
| Presto | WebKit | Gecko | ||||||||||||||||||||||
position: fixed is a problem I describe in this blog post.
Relative to which viewport is the element fixed?
| Property | Opera Mobile | Opera Mini | iPhone | Android | Symbian | S40 | Dolfin | Black |
Palm | Phantom | Obigo | Bolt | Firefox | MicroB | IE Mobile | Black |
Net |
Obigo | UCWeb | |||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Presto | WebKit | Gecko | ||||||||||||||||||||||
|
position: fixed
|
hop |
layout | layout | depends | Visual | layout | hop |
hop |
layout | layout | hop |
No | Gone | hop |
layout | No | ||||||||
|
||||||||||||||||||||||||