Fixing a Missing or Broken Viewport Tag
A page without a viewport meta tag looks fine on a laptop and wrong on a phone: the browser lays it out as if the screen were a desktop monitor, then shrinks the whole thing so visitors have to pinch and zoom to read it.
The fix is a single line in the head, but the line is often missing from older themes and hand-built pages, or it is present with settings that stop people zooming. This guide covers the correct tag, the settings to avoid, the phone-specific problems it interacts with, and how to find the elements that still push a page wider than the screen.
Why phones need to be told
When smartphones arrived, almost every website was built for a desktop screen. To avoid breaking them, mobile browsers adopted a compromise: unless a page says otherwise, lay it out on a virtual canvas roughly as wide as a desktop window, typically around 980 CSS pixels, and scale it down to fit the phone. That default is still in place today. It is the reason an old page appears as a tiny, complete desktop layout on a phone.
The viewport meta tag switches that compromise off. It tells the browser to make the layout width equal to the width of the device and to start at normal zoom. Only then do the media queries in a responsive stylesheet fire at the right sizes. This is the key point: a responsive stylesheet without a viewport tag does not behave responsively on phones, because the browser reports a desktop-sized width to the CSS.
<meta name="viewport" content="width=device-width, initial-scale=1">
| Part | What it does |
|---|---|
width=device-width | Sets the layout width to the width of the screen in CSS pixels, so a phone reports something like 390 or 412 rather than 980 |
initial-scale=1 | Starts the page at 100% zoom, and on some browsers keeps the layout stable when the phone is turned sideways |
Include both. Older advice suggested adding shrink-to-fit=no, which dealt with a behaviour
in a Safari version from years ago; current browsers do not need it.
Why it matters for search
Google indexes and ranks pages using the version a smartphone crawler sees, so the phone experience is the one that counts. Google retired its standalone Mobile-Friendly Test and the Mobile Usability report in Search Console at the end of 2023, so those tools can no longer confirm the problem for you. Lighthouse and the Meta Tag Analyzer still check for the tag.
Viewport values that cause problems
A viewport tag that is present but wrong can be worse than one that is missing, because it looks correct at a glance. These are the settings found most often in audits:
| Setting | Effect | What to do |
|---|---|---|
user-scalable=no | Tries to stop visitors pinching to zoom | Remove it. It fails the WCAG requirement to allow text to be resized |
maximum-scale=1 | Caps zoom at 100%, which also blocks zooming | Remove it, or set it no lower than 5 if something insists on a value |
width=1024 or another fixed number | Forces a desktop layout width on every phone | Replace with width=device-width |
initial-scale=0.5 or similar | Starts the page zoomed out | Use initial-scale=1
and fix the layout instead |
| Semicolons between values | Some browsers tolerate them, others log a warning and may ignore parts | Separate values with commas |
| Two viewport tags | Which one applies depends on the browser | Keep one, in the layout that owns the head |
| Tag added by JavaScript | The first layout happens before the script runs | Put it in the server-rendered HTML, near the top of the head |
Why blocking zoom is an accessibility failure
WCAG 2.2 success criterion 1.4.4, Resize Text, asks that text can be enlarged to 200% without losing
content or function, and 1.4.10, Reflow, asks that content works at a width of 320 CSS pixels without
scrolling in two directions. People with low vision rely on pinch zoom on phones. Automated checkers
such as axe flag user-scalable=no and low maximum-scale values for this reason.
Safari on iPhone has ignored user-scalable=no by default for several years for exactly
this reason, but Chrome on Android and other browsers still honour it. So a tag that blocks zoom may
seem harmless when tested on an iPhone and still lock out Android users.
Diagnosing viewport problems
Three quick checks tell you almost everything.
- Is the tag in the HTML? Fetch the raw page and search for it. If nothing comes back,
the tag is missing from the template, or a script adds it later.
curl -s https://example.co.uk/ | grep -i 'name="viewport"' - What width does the browser report? Open the page on a phone, or in the device toolbar
of browser developer tools, and run
window.innerWidthin the console. A value near 980 on a phone-sized screen means the viewport tag is not working. - Does the page scroll sideways? Swipe left on a phone. If the page moves, something is wider than the screen, even though the viewport is correct. That is a layout problem, covered below.
Test a sample of templates, not only the home page. Old landing pages, legacy blog layouts, embedded booking forms and pages built by a separate page-builder canvas often have their own head and their own copy of the tag, or none at all.
The fix, step by step
Step 1
Check the viewport tag the server sends
Run one page of each template through the Meta Tag Analyzer, then fetch the same addresses
with curl and search for name="viewport". Record for each template whether
the tag is missing, duplicated, added by a script, or present with a problem value such as a fixed width
or user-scalable=no. This tells you how many layout files need changing, which is usually
far fewer than the number of affected pages.
Step 2
Add the standard tag once
Add
<meta name="viewport" content="width=device-width, initial-scale=1"> to the head of
the shared layout, directly after the charset declaration and before stylesheets. If a theme, plugin
and page builder each print one, keep the copy in the layout that controls the head and switch the others
off. Do not add a second tag to override the first, because browsers do not agree on which copy wins.
Step 3
Remove zoom restrictions
Delete
user-scalable=no, user-scalable=0 and any maximum-scale below
5 from the tag. These were often added to stop layouts looking broken when zoomed, or to stop accidental
zooming on web apps. Both are better solved in the layout itself. Zooming is how many people with low
vision read on a phone, and blocking it fails the WCAG requirement to allow text to be resized.
Step 4
Stop phones zooming into form fields
Safari
on iPhone zooms the page when someone taps into an input, select or textarea whose text is smaller than
16 CSS pixels, and does not zoom back out. That is usually why developers added maximum-scale=1.
Fix the cause instead by giving form controls a font size of at least 16px, or 1rem
with a 16 pixel root, which stops the zoom without taking zoom away from anyone.
Step 5
Handle notches and on-screen keyboards
Only
if your design fills the whole screen edge to edge, add viewport-fit=cover to the tag and
pad fixed headers, footers and buttons with env(safe-area-inset-top) and the matching bottom,
left and right values, so nothing sits under a notch or home bar. If a fixed footer is hidden by the
on-screen keyboard, test the interactive-widget value in browsers that support it, rather
than removing zoom.
Step 6
Find elements wider than the screen
With
the device toolbar set to a narrow width such as 320 pixels, run a console snippet that lists elements
whose right edge is past the screen width, then fix each one. The usual culprits are images without max-width: 100%,
tables and code blocks with no scrolling wrapper, fixed pixel widths, long unbroken web addresses, embedded
maps and widths set to 100vw, which includes the scrollbar.
Step 7
Test on real widths and rerun the analyzer
Purge page and CDN caches, then load each template on a real phone in portrait and landscape, pinch to zoom, tap into a form field and swipe sideways to check nothing moves. Run Lighthouse for its viewport audit, then run the Meta Tag Analyzer again on the same sample of pages to confirm a single, correct viewport tag now appears on every template.
Content that is still wider than the screen
A correct viewport tag makes the layout width match the phone, but it does not shrink anything that has been given a fixed width. Those elements poke out past the right edge and the whole page scrolls sideways. This snippet, pasted into the console with a phone-sized window, outlines and lists the offenders:
const w = document.documentElement.clientWidth;
document.querySelectorAll('body *').forEach(el => {
if (el.getBoundingClientRect().right > w + 1) {
el.style.outline = '2px solid red';
console.log(el);
}
});
Common fixes, in the order they usually come up:
- Images and video. Add
img, video { max-width: 100%; height: auto; }to the base stylesheet. Keep the width and height attributes in the HTML so the browser can reserve space. - Tables. Wrap wide data tables in a container with
overflow-x: auto, so the table scrolls inside its box rather than the page scrolling. - Code and long addresses. Use
overflow-wrap: anywhereon body text so long links break, and a scrolling container for code samples. - Fixed widths. Replace
width: 600pxwithmax-width: 600pxor a percentage. - 100vw. On desktop browsers with visible scrollbars,
100vwis wider than the space available. Use100%for full-width sections. - Third-party embeds. Booking widgets, maps and social embeds often set their own width. Most offer a responsive option; if not, a wrapper with a maximum width helps.
overflow-x: hidden on the body as
a first resort. It cuts off content rather than fixing it, can break sticky positioning, and hides the
problem from the next person who looks.Where the tag lives on common platforms
| Platform | Where to look | Notes |
|---|---|---|
| WordPress classic themes | header.php, inside the head | Most maintained themes include it. Very old themes may not; add it in a child theme |
| WordPress block themes | Printed by WordPress core | If you see two, a plugin or custom snippet is adding a second one |
| Shopify | layout/theme.liquid | Also check password.liquid and any alternate layouts |
| Next.js App Router | Added automatically | Customise it with the viewport
export in a layout, not with a hand-written meta tag |
| Static sites and generators | The base layout file | Hand-built sites often have one copy per page; search the whole project |
| Email templates | The head of the email HTML | Some email clients respect it; it does no harm there |
If your site uses a separate mobile address such as m.example.co.uk, the mobile pages
need the tag as well. Separate mobile sites are harder to keep consistent, and a single responsive site
with one viewport tag avoids a whole class of problems.
Stopping it coming back
- One owner for the head. Decide which file prints the viewport tag and make sure nothing else does. Duplicates usually return when a page builder or plugin is added.
- A layout check in testing. Automated accessibility tests catch zoom restrictions, and a visual test at 320 pixels wide catches horizontal overflow before release.
- Base styles that forgive. A small set of defaults, such as images with a maximum width of 100% and scrolling wrappers for tables, prevents most overflow before anyone writes page-specific CSS.
- Check new templates. Landing pages, campaign microsites and embedded forms are where a missing viewport tag most often reappears.
Once phones lay the page out correctly, layout stability and speed on mobile are the next things to look at; the mobile Core Web Vitals guide covers those. The Meta Analyzer Guide explains the other head checks.
1. What is the correct viewport meta tag?
For almost every website it is a single line in the head: meta name viewport with the content width=device-width, initial-scale=1. The first part makes the layout as wide as the screen and the second starts the page at normal zoom. Place it once, near the top of the head after the charset declaration. Adding more values is rarely needed. The main exception is viewport-fit=cover, for designs that deliberately fill the screen around a phone's notch or rounded corners.
2. Why does my responsive site still look tiny on phones?
Because the viewport tag is missing, duplicated with a bad value, or added by a script after the first layout. Without a working tag, mobile browsers lay the page out at a desktop-like width of around 980 CSS pixels and shrink it, so your media queries for small screens never apply. Check the raw HTML for the tag, and run window.innerWidth in the console on a phone. A number close to 980 confirms the viewport is not being applied.
3. Is user-scalable=no bad for SEO?
It is primarily an accessibility problem rather than a ranking one. Blocking pinch zoom stops people with low vision from enlarging text, which fails the WCAG success criterion on resizing text, and accessibility checkers flag it. Safari on iPhone ignores the setting by default now, but other browsers still apply it. There is no benefit that outweighs the harm, so remove user-scalable=no and any low maximum-scale value, and solve the underlying layout issue instead.
4. How do I stop iPhone zooming in when someone taps a form field?
Safari on iPhone zooms in when a form control's text is smaller than 16 CSS pixels, so the reader can see what they are typing. The reliable fix is to set the font size of inputs, selects and textareas to at least 16 pixels. Many sites instead add maximum-scale=1 to the viewport tag, which does stop the zoom but also stops people zooming deliberately, and it fails accessibility checks. Changing the font size fixes the cause without that side effect.
5. Does Google still check mobile-friendliness?
Google indexes pages using its smartphone crawler, so the mobile version of a page is the one it evaluates. It retired the standalone Mobile-Friendly Test and the Mobile Usability report in Search Console at the end of 2023, so those are no longer available as checks. Lighthouse, which is built into Chrome's developer tools and PageSpeed Insights, still tests for a viewport tag, and the Meta Tag Analyzer reports whether the tag is present and correctly configured.
6. My viewport tag is correct but the page scrolls sideways. Why?
The viewport tag only sets the width of the layout. If an element inside the page has been given a fixed width wider than the screen, such as a large image, a data table, a long unbroken link or an embedded widget, it will push past the edge and make the page scroll horizontally. Use the console snippet in this guide at a narrow width to outline those elements, then give each one a maximum width or a scrolling wrapper.
7. Do I need viewport-fit=cover?
Only if your design is meant to run edge to edge on phones with notches or rounded corners, for example a full-bleed hero or a fixed bottom bar. Without it, browsers keep content inside the safe area and fill the edges with the page background, which is fine for most sites. If you do add it, you must also pad fixed elements using the env safe-area-inset values, or buttons and menus can end up hidden under the notch or the home indicator.
The Meta Tag Analyzer reads the head of your page and checks the title, description, canonical, robots directives, viewport configuration, Open Graph and X card tags, then lists each finding with the guide that fixes it.
Open Meta Tag Fixes โ