What is vh in css

Content on WhatAnswers is provided "as is" for informational purposes. While we strive for accuracy, we make no guarantees. Content is AI-assisted and should not be used as professional advice.

Last updated: April 1, 2026

Quick Answer: VH (viewport height) is a CSS unit that represents 1% of the viewport's height. It's used to make responsive designs that scale relative to the browser window size, making it useful for full-screen layouts and dynamic sizing.

Key Facts

Understanding Viewport Height Units

The vh unit in CSS stands for viewport height and is part of a set of relative length units that respond to the browser window dimensions. 1vh is equal to 1% of the current viewport height, so 100vh fills the entire visible height of the browser window. This makes vh units particularly useful for modern web design where responsive layouts are essential.

How VH Works in Practice

When you set an element to 50vh, that element will be exactly half the height of the visible browser window, regardless of the content or parent container. This scaling happens automatically whenever the viewport is resized. VH units are calculated fresh on every layout calculation, ensuring your design remains responsive without media queries.

Common Use Cases

Important Considerations

One important consideration is how mobile browsers handle vh. Many mobile browsers include the address bar in their viewport calculations, which means 100vh might be taller than the visible area. Some developers use alternative solutions like JavaScript-based measurements for mobile to account for this behavior. Additionally, the vh unit doesn't account for horizontal scrollbars on desktop browsers, potentially causing layout shifts.

Comparison with Other Units

Unlike fixed pixel units (px), vh units scale with the viewport, making them more responsive. Compared to percentage (%) units which depend on the parent container, vh is independent of parent element size. This makes vh ideal for full-screen components while percentage is better for content-dependent sizing.

Related Questions

What is vw in CSS?

VW stands for viewport width and represents 1% of the viewport's width. It works similarly to vh but measures horizontal dimensions instead of vertical ones.

What's the difference between vh and percentage units?

VH units are relative to the viewport height regardless of parent container, while percentage units are relative to the parent element's height. This makes vh better for full-screen layouts.

Can I use vh on mobile devices?

Yes, but mobile browsers may handle vh differently by including the address bar in calculations, potentially causing layout issues. Testing on actual devices is recommended.

Sources

  1. MDN - CSS Values and UnitsCC-BY-SA-2.5
  2. W3C - CSS Values and Units ModuleW3C-Document

Missing an answer?

Suggest a question and we'll generate an answer for it.