Course contentsShow
← Web Development
Lesson 384 of 2,9827. Responsive DesignFree lesson

Viewport Units: vw, vh, vmin, vmax

Using viewport-relative units for full-height sections and responsive typography that scales with screen size.

Viewport Units: vw, vh, vmin, vmax

You'll learn how to size elements relative to the browser window for truly responsive layouts.

What Are Viewport Units?

Viewport units are CSS measurements based on the size of the browser window itself. Unlike percentages (which relate to a parent element), viewport units always refer to the visible screen area:

  • vw (viewport width): 1vw = 1% of the viewport's width
  • vh (viewport height): 1vh = 1% of the viewport's height
  • vmin: 1vmin = 1% of the viewport's smaller dimension
  • vmax: 1vmax = 1% of the viewport's larger dimension

Think of viewport units like measuring your furniture relative to your room size rather than relative to your table. If your room changes size, the furniture measurements automatically adjust.

Common Use Cases

Full-height hero sections:

.hero {
  height: 100vh; /* Always fills full viewport height */
}

Responsive typography that scales with screen size:

h1 {
  font-size: 5vw; /* Title grows/shrinks with viewport */
}

Square elements on any screen:

.square {
  width: 50vmin; /* Always square, based on smaller dimension */
  height: 50vmin;
}

Why They Matter

Viewport units eliminate guesswork for full-screen sections and create text that naturally scales across devices. A 100vh section guarantees your content fills exactly one screen, perfect for landing pages or app-like interfaces.

Key Takeaway: Viewport units (vw, vh, vmin, vmax) size elements relative to the browser window, enabling full-height sections and truly responsive typography that adapts to any screen size.