Web Technology Basics
For a page with responsive design that also supports smartphones, which of the following is the main purpose of writing <meta name="viewport" content="width=device-width, initial-scale=1"> in <head>?
- ATo make the width used for laying out the page match the device's screen width and display it without shrinking
- BTo have the server automatically regenerate images to match the resolution of the device's screen
- CTo display the page only in PC browsers and refuse access from smartphones
Show answer and explanation
Answer: A. To make the width used for laying out the page match the device's screen width and display it without shrinking
Without this setting, a smartphone browser lays out the page at a wide width that assumes a page designed for PCs (generally around 980px) and then shrinks it to fit on the screen. width=device-width makes the layout width match the device's screen width, and initial-scale=1 sets the initial zoom to 100%. On top of that, CSS media queries (for example @media (max-width: 600px)) switch the layout and text size according to the screen width.
- A. Correct. It makes the layout width match the screen width and displays the page at a zoom level that does not shrink it.
- B. To have a browser choose an image that fits the screen, the srcset attribute of the img element and the like are used. The viewport setting does not make the server generate images.
- C. The viewport setting decides the display width and zoom; it has no function for refusing access.