The viewport size differs depending on the device, typically smaller on mobile phones compared to computer screens.
In the past, web pages were primarily designed for computer screens with static layouts and fixed sizes. However, with the emergence of tablets and mobile phones, these fixed-size web pages became too large to fit within the viewport. As a result, browsers on these devices resorted to scaling down the entire web page to accommodate the screen size.
While this approach provided a quick fix, it was not without its flaws.
HTML5 introduced a technique for web designers to manage the viewport using the <meta> tag.
It is recommended to incorporate the following <meta> viewport element into all your web pages:
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″> |
This provides instructions to the browser regarding how to manage the dimensions and scaling of the page.
The “width=device-width” segment establishes the page width to adapt to the screen width of the device, which may vary depending on the device.
The “initial-scale=1.0” segment sets the initial zoom level when the page is initially loaded by the browser.
Below is an example of a web page without the viewport meta tag, and then the same web page with the viewport meta tag:
Note: If you are accessing this page using a smartphone or tablet, you can tap on the two links provided above to observe the contrast. |
Users are accustomed to vertical scrolling on both desktop and mobile devices, but horizontal scrolling or zooming out to view the entire web page can lead to a subpar user experience.
Here are some additional guidelines to adhere to: