Viewport Meta Tag
debt(d3/e1/b2/t5)
Closest to 'default linter catches the common case' (d3), since Lighthouse (the listed tool) automatically flags missing viewport tags and zoom-disabling directives via its code_pattern, but a forgotten tag is otherwise silent in desktop testing.
Closest to 'one-line patch' (e1), the quick_fix is literally adding/correcting a single meta tag in the head and removing user-scalable=no.
Closest to 'localised tax' (b3) but slightly lighter; applies_to is web/browser only and it's a single head element, imposing minimal ongoing weight on maintainers though responsive CSS depends on its presence.
Closest to 'notable trap' (t5); the misconception that the tag alone makes a site responsive is a documented gotcha most devs eventually learn, and the user-scalable=no accessibility pitfall reinforces the trap.
Also Known As
TL;DR
Explanation
The viewport meta tag is a single HTML element placed in the document head that instructs mobile browsers how to control the page's dimensions and scaling. Without it, mobile browsers assume a desktop-width layout viewport (typically 980px) and shrink the rendered page to fit the screen, forcing users to pinch-zoom and scroll horizontally. The canonical declaration is `<meta name="viewport" content="width=device-width, initial-scale=1">`, which sets the layout viewport to match the device's screen width in CSS pixels and renders the page at 1:1 zoom on first load. The `content` attribute accepts a comma-separated list of directives: `width` (a pixel value or the keyword `device-width`), `height`, `initial-scale`, `minimum-scale`, `maximum-scale`, and `user-scalable`. Modern responsive design depends on this tag because CSS media queries and `device-width` units only behave as expected when the layout viewport equals the device width. The tag is not a CSS property and not a JavaScript API - it is static markup that the browser reads during initial parsing, so it must appear in the served HTML rather than being injected after render. Avoid disabling user scaling with `user-scalable=no` or `maximum-scale=1` because that breaks pinch-to-zoom, which many users with low vision rely on. Setting it correctly is foundational: every responsive layout, fluid grid, and mobile-first stylesheet assumes the viewport has been declared. It is one line, costs nothing at runtime, and its absence is one of the most common reasons a site looks broken on phones.
Common Misconception
Why It Matters
Common Mistakes
- Forgetting the tag entirely, so the browser falls back to a ~980px desktop viewport and shrinks the page.
- Setting `user-scalable=no` or `maximum-scale=1`, which disables pinch-to-zoom and fails WCAG zoom requirements.
- Using a fixed pixel `width` like `width=320` instead of `width=device-width`, breaking layout on other screen sizes.
- Injecting the tag via JavaScript after load instead of serving it in the initial HTML head.
- Placing the tag outside the document head where the browser may ignore it.
Avoid When
- The document is a non-rendered fragment or email template where mobile browser viewport rules do not apply.
- You are building a desktop-only internal tool that will never be accessed on a mobile device and has fixed-width layout requirements.
When To Use
- Any public-facing web page that should render correctly on phones and tablets.
- Whenever you rely on CSS media queries or mobile-first responsive styles that assume device-width sizing.
Code Examples
<!doctype html>
<html>
<head>
<title>My Site</title>
<!-- No viewport tag: mobile renders at ~980px and shrinks -->
<!-- Or worse, zoom disabled: -->
<meta name="viewport" content="width=device-width, user-scalable=no, maximum-scale=1">
</head>
<body>...</body>
</html>
<!doctype html>
<html>
<head>
<title>My Site</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>...</body>
</html>