Skip to content

Viewport

Easy — everyone uses thisFrontend

ELI5 — The Vibe Check

The viewport is the visible area of a webpage in the user's browser window. It changes depending on the device — small on a phone, huge on a 4K monitor. CSS uses viewport units like vw (viewport width) and vh (viewport height) so you can size things relative to the screen.

Real Talk

The viewport is the visible area of a web document as rendered in the browser. Viewport dimensions are exposed via window.innerWidth/innerHeight. CSS viewport units (vw, vh, vmin, vmax, svh, dvh) size elements relative to the viewport. The tag controls how browsers scale pages on mobile.

Show Me The Code

/* 100% of viewport width and height */
.hero {
  width: 100vw;
  height: 100vh;
}

/* Use dvh for mobile — accounts for browser chrome */
.full-screen {
  height: 100dvh;
}

When You'll Hear This

"The modal should fill the viewport on mobile." / "Use dvh instead of vh on mobile — vh doesn't account for the address bar."

Made with passive-aggressive love by manoga.digital. Powered by Claude.