Skip to Content
UX Patterns for Devs GPT is now available! Read more →
GlossaryViewport

Viewport

The viewport is the user’s visible area of a web page. It varies with the device - it will be smaller on a mobile phone than on a computer screen. The viewport is fundamental to responsive web design and affects how content is displayed and interacted with across different devices.

Types of Viewports

Visual Viewport

The part of the page that’s currently visible in the browser window. When users pinch-zoom, the visual viewport gets smaller while showing a zoomed-in portion of the layout viewport.

Layout Viewport

The area where the browser renders the website. On mobile devices, this is typically wider than the visual viewport to accommodate desktop sites.

Viewport Meta Tag

Control how your page displays on mobile devices:

<meta name="viewport" content="width=device-width, initial-scale=1.0">

Common attributes:

  • width: Sets viewport width (device-width or specific value)
  • initial-scale: Sets initial zoom level
  • maximum-scale: Maximum zoom level allowed
  • minimum-scale: Minimum zoom level allowed
  • user-scalable: Whether users can zoom (avoid disabling zoom for accessibility)

Viewport Units

CSS units relative to viewport dimensions:

  • vw: 1% of viewport width
  • vh: 1% of viewport height
  • vmin: 1% of viewport’s smaller dimension
  • vmax: 1% of viewport’s larger dimension
  • dvh/dvw: Dynamic viewport height/width (accounts for browser UI)
  • svh/svw: Small viewport height/width (minimum size)
  • lvh/lvw: Large viewport height/width (maximum size)

Common Use Cases

Responsive Design

Adapting layouts based on viewport size using media queries:

@media (max-width: 768px) { /* Mobile styles */ }

Full-Height Sections

Creating sections that fill the viewport:

.hero { height: 100vh; } /* Note: On mobile, consider using dynamic viewport units (dvh/svh/lvh) to account for browser chrome that hides/shows on scroll */

Viewport-Based Typography

Scaling text based on viewport size:

h1 { font-size: clamp(2rem, 5vw, 4rem); }

Mobile Considerations

  • Safe Areas: Account for device notches and rounded corners
  • Orientation Changes: Handle landscape/portrait transitions
  • Browser Chrome: Consider address bars that hide/show on scroll
  • Pinch-to-Zoom: Ensure accessibility by not disabling zoom

Testing Viewports

Tools for testing across viewports:

  • Browser DevTools responsive mode
  • BrowserStack or similar services
  • Physical device testing
  • Viewport resizer extensions

Viewport considerations are crucial for:

Best Practices

  1. Always include the viewport meta tag
  2. Test on real devices, not just browser tools
  3. Consider both portrait and landscape orientations
  4. Account for dynamic viewport changes (mobile browsers)
  5. Ensure critical content is above the fold
  6. Use viewport units carefully with fallbacks

Stay updated with new patterns

Get notified when new UX patterns are added to the collection.

Last updated on