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
Key Facts
- 1vh equals 1% of the viewport height at any given time
- VH units are responsive and automatically adjust when the browser window is resized
- Commonly used with other units like VW (viewport width) for responsive sizing
- Mobile browsers may handle vh differently, sometimes including or excluding the address bar
- 100vh creates a full-height element that spans the entire visible browser window
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
- Full-screen hero sections (height: 100vh)
- Split-screen layouts with equal height sections
- Hero images and banners that scale with the viewport
- Modal dialogs and overlay components
- Multi-section pages where each section fills the viewport
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.
More What Is in Daily Life
Also in Daily Life
More "What Is" Questions
Trending on WhatAnswers
Browse by Topic
Browse by Question Type
Sources
- MDN - CSS Values and UnitsCC-BY-SA-2.5
- W3C - CSS Values and Units ModuleW3C-Document
Missing an answer?
Suggest a question and we'll generate an answer for it.