Explore Bato Web Agency Webflow Certified Partner Profile Explore Bato Web Agency Webflow Certified Partner Profile

What is the difference between the layout viewport and the visual viewport?

Illustration without a description Illustration without a description

The layout viewport is the coordinate space CSS uses to lay out most page content, while the visual viewport is the portion currently visible to the user. On mobile, pinch zoom and the on-screen keyboard can make the visual viewport smaller without changing the underlying layout viewport in the same way.

 

Media queries and viewport-width units generally describe the layout viewport. Fixed-position elements are laid out against viewport rules, but users may see only part of that area after zooming. Code that assumes window.innerHeight always equals visible space can place a button behind a keyboard.

 

The Visual Viewport API exposes values such as visualViewport.width, height, offsetTop and scale. It is useful for carefully positioning overlays or editing tools during pinch zoom or keyboard display. Feature detection and cleanup of event listeners are required.

 

Do not build ordinary responsive layout in JavaScript from visual viewport events. CSS, dynamic viewport units and natural document flow handle most pages more reliably. Visual viewport resize and scroll events can fire frequently, so heavy handlers may create jank.

 

Test zoom, orientation and form entry on actual mobile browsers. Confirm dialogs and fixed actions remain reachable when the keyboard opens. Use the layout viewport for page structure and the visual viewport only when a feature must react to the user’s currently visible window. Keep the rule beside the component it controls and document the reason for the threshold or constraint. This makes future changes easier to evaluate and prevents an unrelated page stylesheet from silently overriding the responsive behavior.