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

How do you inspect the actual CSS viewport size on a phone?

Illustration without a description Illustration without a description

Inspect a phone’s CSS viewport through remote developer tools or a temporary diagnostic readout on the page. window.innerWidth and window.innerHeight report the layout viewport in CSS pixels, while visualViewport reports the currently visible area affected by zoom, browser chrome and the keyboard. Record both when debugging mobile overlays.

 

const viewport = {
layoutWidth: window.innerWidth,
layoutHeight: window.innerHeight,
visibleWidth: window.visualViewport?.width,
visibleHeight: window.visualViewport?.height,
offsetTop: window.visualViewport?.offsetTop,
scale: window.visualViewport?.scale
};
console.table(viewport);

 

The values are CSS pixels, not the display’s physical hardware pixels. Device pixel ratio describes the relationship between them, but multiplying dimensions is rarely useful for layout debugging. Media queries normally respond to the CSS viewport, so compare their matches with the same unit system.

 

Use matchMedia('(max-width: 48rem)').matches to verify a suspected media condition. The document element’s client width can differ from innerWidth when a scrollbar occupies space. On most phone layouts the difference is small, yet recording both can explain a boundary that behaves differently on desktop.

 

Listen to resize events only while diagnosing dynamic behavior. The visual viewport can change repeatedly as the address bar animates or the keyboard opens. Show the values in a small fixed debug panel if the remote console is inconvenient, then remove the panel before production because it can change layout and cover controls.

 

Capture measurements before and after rotation, keyboard opening and pinch zoom. Pair every value with the browser name, device orientation and zoom state. A screenshot alone does not reveal which viewport was measured, and a named phone preset may use a different browser-chrome state from the physical device.