One meta tag in the head decides whether your page is a real responsive page or a zoomed-out desktop page pretending to be mobile. It is short, it is required, and almost every layout problem that looks unfixable on a phone comes from getting it wrong or leaving it out.
The previous lesson in this module covered "Why Build Mobile-First and Scale Up?", and the next lesson in this module is about "How Do You Choose Breakpoints Without Guessing?".
What does the tag look like?
<meta name="viewport" content="width=device-width, initial-scale=1">
Two settings, and both matter. width=device-width sets the layout viewport to the width of the screen, measured in CSS pixels. initial-scale=1 sets the starting zoom so that one CSS pixel is one device pixel.
Without the tag, a mobile browser assumes a layout viewport of about 980 pixels wide and scales the whole page down to fit the screen. Your 320-pixel-wide design is scaled to a third, the text becomes unreadable, and any touch target becomes tiny. The page is not broken — it is being displayed as a zoomed-out desktop page.
without the tag
layout viewport: 980 CSS pixels wide
your content is scaled to ~0.33
a 16px font renders at about 5px
tap targets are a third of the size
with the tag
layout viewport: the width of the screen
16px font renders at 16px
Why should you never disable zooming?
Because people zoom. A reader with low vision, a reader on a small screen in bright sunlight, a reader reading a table of numbers — all of them may need to enlarge the text, and blocking that makes the page unusable for them.
<!-- do not do this -->
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
This used to be common advice, on the theory that it stopped accidental double-tap zooming and kept the layout stable. Both problems have better solutions now. Accidental double-tapping is handled by setting touch-action on the specific elements that should not zoom, and a layout that moves when zoomed is a layout that needs a maximum width rather than a blocked pinch.
Blocking zoom is also an accessibility failure that is easy to test: turn on zoom in your phone's settings, or pinch, and if the page will not enlarge, that is the bug.
What are the other settings?
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
viewport-fit=cover extends the layout area to cover the rounded corners and the notch on a phone. It only makes sense together with safe-area insets, because the content would otherwise run under the notch.
.app-bar {
padding-left: max(1rem, env(safe-area-inset-left));
padding-right: max(1rem, env(safe-area-inset-right));
padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
}
The max() combination is the standard pattern: use your own spacing, but take the larger of it and the system inset. The maximum-scale and minimum-scale settings exist for the same reason as user-scalable, and the same advice applies — leave them out.
How does zooming interact with media queries?
There is a subtlety here that catches people out. The width used by a media query is the layout viewport, which changes when the reader zooms in. So a reader who zooms to 200 percent on a 400-pixel-wide phone gets a layout viewport of 200 pixels, and a min-width: 48rem query stops matching.
screen width 400px, zoom 200%
layout viewport becomes 200px
a min-width: 48rem (768px) query no longer matches
the page reverts to the small-screen layout — which is correct
This is the intended behaviour and it is why a zoomed-in page stays readable rather than being a cropped version of the desktop layout. The lesson is that your small-screen layout has to be genuinely usable, because it is what a zoomed-in reader sees.
How do you test it?
Two checks. First, put the meta tag in and remove it: the page should visibly change on a phone, going from a scaled-down desktop page to a real layout. Second, type your own page URL into a mobile device's browser and check the layout — or use the device emulation mode in the developer tools, which is the same rendering engine.
what to look for in device emulation
the page is not scaled down
the text is the size you wrote
the layout is the one your media queries produce
pinching to zoom works
One more check worth doing: turn on the browser's own zoom and confirm the layout still works. A layout that only holds together at exactly 100 percent is not really responsive, whatever the meta tag says.
What is the difference between the meta tag and the viewport units?
Two different things are both called "the viewport", and they are easy to mix up. The <meta name="viewport"> tag tells the browser how wide the page should think the screen is. The viewport units - vw, vh and their relatives - are CSS values that resolve against that same width.
Without the meta tag, a mobile browser assumes the page was designed for a fixed width of around 980 pixels and scales it down to fit. Your carefully responsive layout is then shrunk into a corner, the text is tiny, and the media queries see a screen that is 980 pixels wide no matter what the real device is.
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Studio</title>
</head>The width=device-width part sets the layout viewport to the width of the device's screen, so your media queries and your vw units both measure the real thing. The initial-scale=1 part sets the starting zoom level to one to one, so the page is not scaled up or down on the first render.
The second half of the puzzle is this: 100vw is the width of the viewport, which on a desktop browser includes the vertical scrollbar. So an element that is width: 100vw is slightly wider than the space you can actually see, and a full-bleed background built that way will show a horizontal scrollbar. The fix is either to use width: 100% on a block element, which already accounts for the scrollbar, or to subtract the scrollbar width with 100vw replaced by a calculation.
/* this overflows horizontally in a desktop browser */
.full-bleed {
width: 100vw;
}
/* this does not */
.full-bleed {
width: 100%;
}And on mobile, the safe area matters. A phone with a notch or a rounded corner reserves some of the screen, and the env() function with the safe-area-inset values tells you how much space is being kept clear. Add that padding to a fixed bottom bar and it will not sit under the home indicator.
Quick reference
width=device-width, initial-scale=1is the standard setting.- Without it, mobile browsers assume a 980-pixel layout and scale the page down.
- Never set
user-scalable=no— it blocks zoom for readers who need it. viewport-fit=covergoes with theenv(safe-area-inset-*)values.- Zooming changes the layout viewport, so the small-screen layout must be genuinely usable.
- Test by toggling the tag and by zooming in the device emulator.
Try it yourself: open one of your pages in device emulation with the viewport tag removed and watch the page shrink. Put it back and confirm the layout is the one your media queries produce. Then zoom in and check that the text stays readable and the page does not break.