Responsive Web Design - Viewport
What is a Viewport?
A viewport is the visible area of a web page for the user.
Viewport can be translated into Chinese as "viewing area".
Mobile browsers place the page in a virtual "window" (viewport), which is usually wider than the screen, so that each web page does not have to be squeezed into a very small window (which would destroy the layout of pages not optimized for mobile browsers). Users can view different parts of the page by panning and zooming.
Setting the Viewport
A commonly used viewport meta tag for pages optimized for mobile web is roughly as follows:
- width: controls the size of the viewport; you can specify a value such as 600, or a special value such as device-width, which is the width of the device (in CSS pixels when zoomed to 100%).
- height: corresponds to width, specifying the height.
- initial-scale: the initial scale ratio, that is, the scale when the page is first loaded.
- maximum-scale: the maximum scale the user is allowed to zoom to.
- minimum-scale: the minimum scale the user is allowed to zoom to.
- user-scalable: whether the user can manually zoom.
The following examples demonstrate the effect of using a viewport versus not using a viewport on mobile devices:
Example 1: Without adding a viewport:Click to view
Example 2: Adding a viewport:Click to view
If you visit on a tablet or phone, you can click to view the effect directly.