|
Partners
|
|
![]() Figure 1: JK homepage with NO "viewport" meta tag. Notice how the mobile
browser zooms outs on the page, pretending it's a desktop browser. |
![]() Figure 2: JK homepage with "viewport" meta tag
and its width set to "device-width". No
automatic zooming out. |
The viewport meta tag supports a handful of other properties for the "content"
attribute:
| Property | Description |
|---|---|
| width | The width of the virtual viewport of the device. Enter a
number (pixels assumed), or the keyword "device-width" to
set the viewport to the physical width of the device's screen. |
| height | The height of the virtual viewport of the device. Enter
a number (pixels assumed), or the keyword "device-height"
to set the viewport to the physical height of the device's screen. |
| initial-scale | The initial zoom of the webpage, where a value of 1.0 means no zoom. |
| minimum-scale | The minimum level the user is able to zoom out of a webpage, where a value of 1.0 means the user isn't able to at all. |
| maximum-scale | The maximum level the user is able to zoom in on a webpage, where a value of 1.0 means the user isn't able to at all. |
| user-scalable | Sets whether the user can zoom in and out of a webpage. Set to yes or no. |
When optimizing a webpage for mobile devices, the first step is to add
the viewport meta tag to the HEAD section of your page, so that mobile
devices refrain from making changes to the zoom level of the webpage
unilaterally. In most cases you'll simply want to set the meta tag's
content property to "width=device-width", so that no
scaling of the page occurs at all, and your CSS media queries will return
the actual dimensions of the device, not the "zoomed out" version's.
To also prevent the device from zooming in on a webpage when its orientation
has been changed from portrait to landscape and visa versa, you can also
throw in an initial-scale and maximum-scale
property and limit both of them to 1:
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
After that, you can get to work with changing your page's layout depending on the device's dimensions, CSS pixel density, and more. Where to take things is up to you and your design sense!
End of Tutorial