Viewport
In a web browser, the viewport is the area of a page that is visible in the window at one moment, measured in CSS pixels. Content outside it appears only when scrolled into view. Browsers separate the layout viewport, which the page is laid out against, from the visual viewport, the part on screen now.
The longer version
MDN's glossary starts from computer graphics, where a viewport is "a polygonal (normally rectangular) area that is currently being viewed", and then gives the browser's meaning: the part of the document being viewed in the browser window. The word also names hardware and software products, which is why search results for it are mixed. The viewport is not the screen and not the whole window, and MDN notes that the browser chrome, the toolbars and tabs around the page, is not part of it.
Two viewports exist because phones let people zoom and bring up keyboards. The layout viewport is the area the page is laid out against, and fixed headers and footers attach to it. The visual viewport is the part showing on the screen at this moment, the same size or smaller. In MDN's words, when the user pinch-zooms the page, opens an on-screen keyboard or a hidden address bar comes back, "the visual viewport shrinks but the layout viewport is unchanged". A send button fixed to the bottom of a chat page that disappears behind the keyboard is a bug of this kind.
The viewport meta tag exists because of an old workaround. MDN explains that some mobile devices render a page in a virtual viewport wider than the screen and shrink the result to fit, for example drawing a page 980 pixels wide on a screen 640 pixels wide. A meta element named viewport with the content width=device-width tells the browser to use the device's own width. MDN warns against using the same tag to switch zooming off, because that stops people with low vision from enlarging the page.
A layout bug belongs to a viewport size. Responsive breakpoints are written against the viewport's width in CSS pixels, and neither the name of the device nor the resolution of its screen fixes that width: the window may not be maximised, the page may be zoomed, or the developer tools may be docked at the side. A report that the menu overlaps the logo on a laptop leaves the developer guessing which layout was showing. The viewport width and height settle it, alongside the device pixel ratio and the device and browser that cross-device testing asks for.
Common questions
What is the viewport in a browser?
The viewport in a browser is the rectangle in which the page is shown: the part of the document visible in the window, without the toolbars, tabs and other browser interface around it. Its size is given in CSS pixels and changes when the window is resized or the page is zoomed.
What is the difference between the layout viewport and the visual viewport?
The layout viewport is the area a page is laid out against, and elements with fixed positions attach to it. The visual viewport is the portion currently visible on the screen. Pinch-zooming or opening an on-screen keyboard shrinks the visual viewport and leaves the layout viewport as it was.
What does the viewport meta tag do?
The viewport meta tag tells a mobile browser how wide to make the viewport and how far to zoom at the start. With the content width=device-width the page is laid out at the device's own width. Without the tag, some mobile browsers lay the page out on a wider virtual viewport and shrink it to fit.
What is the difference between viewport size and screen resolution?
Screen resolution is the number of hardware pixels on the display. Viewport size is the area the browser gives the page, in CSS pixels, and is smaller whenever the window is not full screen, the page is zoomed or the display has a device pixel ratio above one. Layout depends on the viewport.
How do you find the viewport size of a page?
Run document.documentElement.clientWidth and document.documentElement.clientHeight in the browser console for the size without scrollbars, or window.innerWidth and window.innerHeight for the size including them. The responsive design mode in the browser's developer tools shows the same dimensions while the window is resized.
What is the difference between a window and a viewport?
The window is the whole browser frame on the screen, with its tabs, address bar and toolbars. The viewport is the rectangle inside it where the page is drawn. Resizing the window resizes the viewport, but showing a bookmarks bar or docking the developer tools shrinks the viewport while the window stays the same size.
How do you add the viewport meta tag?
Put <meta name="viewport" content="width=device-width, initial-scale=1"> inside the head of every page. width=device-width lays the page out at the device's own width and initial-scale=1 opens it unzoomed. Leave out maximum-scale=1 and user-scalable=no, which stop people from zooming in to read.
What are viewport units such as vh, vw and dvh?
MDN defines 1vh as one hundredth of the layout viewport's height and 1vw as one hundredth of its width. On phones, 100vh ignored the address bar sliding in and out, so a full-height element overflowed the screen. The newer units fix that: svh assumes the browser's toolbars are showing, lvh assumes they are hidden, and dvh follows them as they move. web.dev reported them available in all three browser engines from Chrome 108.
What are common viewport sizes?
Current large phones are a little over 400 CSS pixels wide in portrait. The YesViz chart lists 440 by 956 for the iPhone 17 Pro Max, 412 by 891 for the Samsung Galaxy S26 Ultra and 448 by 997 for the Pixel 9 Pro XL. Desktop viewports vary far more, because windows are rarely maximised, so a bug report should give the measured size rather than the device name.
Bug reports that arrive ready to triage.
Collect replay, console, network and browser context with the Free plan.