Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

vh and vw size CSS values against the viewport’s height and width; vmin and vmax follow whichever viewport dimension is shorter or longer. For mobile layouts, the newer svh, lvh, and dvh units help you choose how an element responds to browser controls such as the address bar.

What do vh, vw, vmin, and vmax mean?

Viewport units are lengths calculated from the viewport rather than from an element’s parent. That differs from a percentage such as width: 50%, which is generally resolved against the containing block. The W3C defines viewport-percentage lengths in its CSS Values and Units Level 4 specification; MDN summarizes the basic formulas in its viewport-relative length reference.

  • vh: 1% of the viewport height. If that height is 800 CSS pixels, 50vh is 400 CSS pixels.
  • vw: 1% of the viewport width. If that width is 1,200 CSS pixels, 25vw is 300 CSS pixels.
  • vmin: 1% of the smaller viewport dimension. It follows the shorter axis, even when orientation changes.
  • vmax: 1% of the larger viewport dimension. It follows the longer axis.

These formulas refer to CSS pixels, not a device’s physical pixel dimensions. In an iframe, the units use that iframe document’s viewport rather than automatically measuring the top-level browser window; see MDN’s viewport-unit reference.

When should you use each viewport unit?

Use vh for height-driven layouts

Use vh when a section’s size should relate to viewport height and the default large-viewport behavior is acceptable. For example, a hero can occupy a substantial part of the screen without requiring a fixed pixel height:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
.hero {
  min-height: 60vh;
  padding: clamp(1rem, 3vw, 3rem);
}

clamp() keeps the padding between a minimum and maximum while allowing it to scale fluidly in between. The values are design choices, not universal recommendations.

Use vw for width-driven sizing

vw is useful for spacing, grids, or type that should respond to viewport width. Unbounded viewport-based typography can become too small on narrow screens or too large on wide ones, so use a clamp() range when readability needs limits. For body text and controls, keep a usable lower bound rather than letting viewport scaling dictate every size.

Use vmin when the shorter axis should control

vmin suits elements that must remain proportionate to the available space in both portrait and landscape, such as a square avatar or a compact shape:

.avatar {
  width: 20vmin;
  height: 20vmin;
}

Use vmax when the longer axis should control

vmax follows the longer side of the viewport. It can suit broad background effects intended to grow with the screen’s largest dimension. Because the longer axis can be especially large in landscape, consider bounding the result with min(), max(), or clamp() if the effect should not expand without limit.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why can 100vh be too tall on mobile?

Mobile browsers may expand or retract interface elements such as the address bar. The layout viewport and the visual viewport are not always the same: pinch zoom, a virtual keyboard, or browser UI changes can shrink the area currently visible without changing the layout viewport in the same way. As a result, a 100vh element may extend behind browser controls instead of matching the currently visible height. MDN explains this distinction in its Visual Viewport API guide.

CSS now provides small, large, and dynamic viewport-unit families to make the intended behavior explicit. MDN documents that the default vh and vw units currently correspond to lvh and lvw, respectively, in its viewport-unit reference.

Rank #3
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
Unit family Reference behavior Useful when Trade-off
svh / svw Small viewport, with browser UI expanded Keeping content within the available space while browser controls are present May leave unused space after browser UI retracts
lvh / lvw Large viewport, with browser UI retracted Stable sizing against the largest viewport Content may sit beneath expanded browser UI
dvh / dvw Dynamic viewport, changing as browser UI expands or retracts Matching the current viewport when fitting the visible area matters more than stable sizing May resize during scrolling
vh / vw Currently map to the large viewport units in MDN’s documented browser behavior Height- or width-based sizing when that large-viewport behavior is acceptable Can share the large-unit overlap behavior on mobile

The W3C specification describes the viewport-unit families, and MDN explains their practical trade-offs in its reference. Choose based on what should happen while browser controls are visible: use a small unit when avoiding overlap is the priority, or a dynamic unit when tracking the changing viewport is worth the possibility of resizing.

How to choose svh, lvh, or dvh

Use svh when a panel should fit the viewport with browser UI expanded and you would rather tolerate extra space after that UI retracts. Use lvh when sizing for the largest viewport is more important than avoiding overlap while browser UI is expanded. Use dvh when the element should follow the changing viewport, accepting that its size can change as the browser interface moves.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A progressive declaration lets browsers that support dynamic units use them while retaining a fallback:

.panel {
  min-height: 100vh;
  min-height: 100dvh;
}

Browsers that understand both declarations apply the later supported value; browsers without support for dvh retain the earlier 100vh rule. If avoiding browser-UI overlap is more important than dynamically filling the available space, use 100svh instead of the dynamic declaration where supported.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Set the viewport meta tag for mobile pages

Viewport units work with the browser’s viewport, so the page needs an appropriate mobile viewport configuration. MDN notes that without a viewport meta tag, some mobile browsers use a fixed initial containing-block width, typically 980 pixels. That can make a responsive layout behave as if its viewport were much wider than the device. Include this in the document’s <head>:

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

See MDN’s viewport meta tag guide and explanation of viewport width and screen width.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Make viewport-based layouts more robust

Viewport-relative sizing is a tool, not a guarantee that content will fit every screen or interaction state. For text and spacing that need limits, combine a viewport unit with rem-based bounds. Then check the states likely to change the available space:

  • Long content that must scroll rather than be clipped.
  • Zoomed pages and orientation changes.
  • Virtual keyboards and expanded or retracted browser controls.
  • Text, buttons, and focus targets that must remain readable and usable.

For a full-screen panel, choose the unit according to the browser-UI behavior you want, and avoid treating a single viewport height as a substitute for testing how the page behaves when the visible area changes.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.