BF50 Black Friday · 50% off all plans
from $5/mo · Auto-applied ---:--:-- Claim 50% off →
Skip to content

Search Seonio

Type a keyword, domain, or paste a URL

Start free with $1 to see full results. Powered by Seonio
Web Development

Viewport: What it is and how to set the meta tag

On phones, one meta tag decides how wide your page is laid out. Without it, visitors see a shrunken desktop page they have to zoom to read.

Monthly searches · viewport
18.1k
Keyword research data
viewport
Viewport: What it is and how to set the meta tag
Click the image to view it full size

In web development, the viewport is the area of the browser window where the page is drawn. Anything outside it stays hidden until you scroll. On a desktop it's roughly the window minus the toolbars; on a phone it's the screen minus the browser's own bars.

Its size isn't the same as the screen resolution. A phone may have a screen over 1,000 physical pixels wide, but the browser works in CSS pixels and might report a viewport of a few hundred pixels. Your layout and your media queries respond to the viewport, not the hardware.

The viewport meta tag

Phones have a habit left over from the early mobile web. Without instructions, a mobile browser assumes the page was built for desktops. It lays the page out on a virtual viewport around 980 pixels wide, then shrinks the result to fit the screen. Text becomes tiny, and media queries written for narrow screens never apply, because the browser thinks it's 980 pixels wide.

One line in the <head> fixes that:

<meta name="viewport" content="width=device-width, initial-scale=1">
  • width=device-width lays the page out at the device's width in CSS pixels.
  • initial-scale=1 starts the page at 100% zoom.

MDN now notes that width=device-width alone is the recommended setting and initial-scale=1 is usually unnecessary. It does help when some content overflows the screen and the browser would otherwise zoom out to fit it, so many sites keep both. Either form is fine; the real fix for overflow is to stop content being wider than the screen.

Other values

Key What it does
width A pixel width (1 to 10,000) or device-width
height A pixel height or device-height; rarely needed
initial-scale Zoom level when the page loads
minimum-scale, maximum-scale Limits on zooming
user-scalable no stops pinch-zoom
interactive-widget Whether the on-screen keyboard resizes the page or only overlays it
viewport-fit cover fills screens with notches and rounded corners

Don't block zoom

user-scalable=no and a low maximum-scale stop people with low vision from enlarging text. The WCAG accessibility guidelines require at least 2× zoom, and MDN warns against disabling it. iOS has ignored these settings by default since iOS 10; on other browsers they still lock people out. See accessibility.

Layout viewport and visual viewport

Browsers actually keep two viewports:

  • The layout viewport is the area the page is laid out in.
  • The visual viewport is the part you can see right now. When you pinch-zoom, it shrinks, while the layout viewport stays the same.

The on-screen keyboard works the same way by default: it shrinks the visual viewport and leaves the layout alone. Set interactive-widget=resizes-content if you want the layout to make room for it instead. An <iframe>, <svg> or <object> also has its own viewport, sized by the element.

Viewport units in CSS

CSS can size things relative to the viewport. 1vw is 1% of its width and 1vh is 1% of its height. On phones that causes a familiar problem: browsers hide the address bar as you scroll and show it again, so the visible height keeps changing.

Newer units let you choose which height you mean:

  • svh: the small viewport, with the browser bars showing. Stable and safe, though it can leave a gap when the bars hide.
  • lvh: the large viewport, with the bars hidden. Plain vh behaves like this, so the bars can cover the bottom of a 100vh element.
  • dvh: the dynamic viewport, which follows the bars as they move. It fits exactly but resizes content while people scroll.

For a full-screen hero on mobile, 100svh is usually the safer choice than 100vh.

Why the viewport matters for SEO

Google indexes and ranks the mobile version of your pages, crawled with a smartphone user agent. This is called mobile-first indexing. A page without a viewport tag still gets indexed, but mobile visitors see a shrunken desktop layout, and that's a poor user experience.

The viewport tag is the first step of responsive design, not all of it. The page also has to fit:

  • Size containers in relative units, such as max-width: 100%, not fixed widths like width: 1200px.
  • Give images max-width: 100% and height: auto so they shrink with the screen. See responsive images.
  • Use media queries to change the layout at the widths where it breaks, not at the widths of particular phones.
  • Watch for anything that causes horizontal scrolling: wide tables, long URLs, code blocks, large absolute positions.

How to check a page

  1. View the page source and confirm the <meta name="viewport"> tag is in the <head>.
  2. Run Lighthouse. It flags a page whose viewport tag is missing or lacks width=, and one with initial-scale below 1, which turns on double-tap zoom and adds a 300 millisecond delay to every tap. Since Lighthouse 13 this check sits in the "Optimize viewport for mobile" insight.
  3. Open your browser's device mode in its developer tools and narrow the window to around 320 pixels. If a horizontal scroll bar appears, something is wider than the viewport.
Seonio

Put it to work on your own site

Keyword research, traffic, backlinks and clustering in one place. Start with a free $1 to test, no card required.