# Viewport

The viewport is the browser area through which a document is viewed and against which many layout and visibility decisions are made.

- Type: term
- Domain: Experience & interface
- Level: Foundational
- Last reviewed: 2026-09-23
- Original: [Soroush’s Product Wiki](<https://wiki.soroush.uk/topic/viewport/>)

## What it means

A viewport is a viewing region for web content. The layout viewport provides a coordinate space used for CSS layout, while a visual viewport can describe the currently visible portion after zooming or an on-screen keyboard changes available space. Mobile viewport metadata influences the initial layout viewport and scale.

## Why it matters

Viewport behavior determines responsive layout, units, media queries, fixed controls, zoom, and what users can currently see. Treating it as a fixed device screen causes failures in split windows, browser chrome, keyboards, and magnification.

## When to use it

Use viewport concepts when designing responsive pages, overlays, full-height regions, virtualized content, or visibility-triggered loading. Prefer flexible layout and account for zoom and dynamic browser UI rather than inferring a device model from dimensions.

## How it works

1. The browser establishes layout and visual viewports for the document context.
2. Viewport metadata can set the initial mobile layout width and scale behavior.
3. CSS media queries and viewport units respond to relevant dimensions.
4. Scrolling and zooming change which portion of the laid-out document is visible.
5. Responsive testing checks resizing, orientation, zoom, keyboards, and embedded contexts.

## A practical example

A checkout keeps its action bar visible above a mobile on-screen keyboard using the visual viewport while allowing the form to reflow at 400% zoom. It avoids assuming the viewport equals the physical screen.

## Where it breaks

Viewport sizes change as browser controls and keyboards appear, viewport units have multiple variants, and embedded documents have their own contexts. Dimensions do not reliably reveal input type, device class, or user capability.

## Common mistakes

- Equating viewport size with physical screen size or device identity.
- Disabling user zoom to hide layout defects.
- Using fixed viewport heights without accounting for dynamic browser controls.
- Positioning overlays without testing on-screen keyboards and magnification.

## Sources

1. [Viewport Concepts](<https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/CSSOM_view/Viewport_concepts>) — MDN Web Docs · Official technical documentation
2. [CSS Viewport Module Level 1](<https://www.w3.org/TR/css-viewport-1/>) — W3C · Web standard

## Related topics

- [Responsive Design](<https://wiki.soroush.uk/topic/responsive-design/>)
- [Adaptive Design](<https://wiki.soroush.uk/topic/adaptive-design/>)
- [Grid System](<https://wiki.soroush.uk/topic/grid-system/>)
