Viewport
The viewport is the browser area through which a document is viewed and against which many layout and visibility decisions are made.
Download Markdown (.md)Soroush’s Product Wiki · https://wiki.soroush.uk/topic/viewport/
01What 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.[1][2]
02Why 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.
03When 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.
04How it works
- The browser establishes layout and visual viewports for the document context.
- Viewport metadata can set the initial mobile layout width and scale behavior.
- CSS media queries and viewport units respond to relevant dimensions.
- Scrolling and zooming change which portion of the laid-out document is visible.
- Responsive testing checks resizing, orientation, zoom, keyboards, and embedded contexts.
05A 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.
06Where 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.
07Sources
- Viewport ConceptsMDN Web Docs · Official technical documentationViewport Concepts
- CSS Viewport Module Level 1W3C · Web standardCSS Viewport Module Level 1