What does vh mean 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 4, 2026

Quick Answer: In CSS, `vh` stands for 'viewport height'. It's a relative unit where 1vh is equal to 1% of the height of the viewport (the browser window's visible area). Therefore, `100vh` means 100% of the viewport's height.

Key Facts

What does vh mean in CSS?

In the world of Cascading Style Sheets (CSS), units are crucial for defining the size and spacing of elements on a web page. Among these units, `vh` is a particularly useful one for creating responsive designs that adapt to different screen sizes. Understanding `vh` is key to mastering modern web layout techniques.

Understanding Viewport Units

Before diving into `vh`, it's important to understand the concept of the 'viewport'. The viewport is the user's visible area of a web page. On a desktop browser, it's the window you see the website in. On a mobile device, it's the screen itself. The dimensions of the viewport can change as the user resizes their browser window or rotates their device.

CSS provides several units that are relative to the viewport's dimensions. These are known as viewport units. The primary viewport units are:

What is vh in CSS?

As mentioned, `vh` stands for 'viewport height'. It is a relative unit that allows you to set the size of an element based on the height of the browser window. For example, if you set an element's height to `50vh`, its height will be exactly half of the viewport's current height, regardless of the user's screen resolution or zoom level.

How to Use vh Units

The `vh` unit can be applied to almost any CSS property that accepts length values, such as `height`, `margin`, `padding`, `font-size`, `top`, `bottom`, `transform`, and more.

Example 1: Full-Height Sections

One of the most common uses of `vh` is to make elements take up the full height of the viewport. This is perfect for creating hero sections or distinct content blocks that span the entire screen height.

.hero-section {height: 100vh;background-image: url('hero-image.jpg');background-size: cover;display: flex;justify-content: center;align-items: center;color: white;text-align: center;}

In this example, the `.hero-section` will always occupy the full height of the user's browser window. This ensures a consistent and immersive experience, especially on the initial load of a webpage.

Example 2: Responsive Typography

You can also use `vh` to make text scales with the viewport height. While not always recommended for primary body text due to potential readability issues on very small screens, it can be effective for headings or call-to-action elements.

h1 {font-size: 8vh;}

This would make the `h1` element's font size dynamically adjust based on the viewport's height. A larger viewport height would result in a larger font size, and vice versa.

Example 3: Spacing and Positioning

`vh` units can also control spacing and positioning relative to the viewport height. For instance, you might want to ensure an element is always a certain distance from the top or bottom of the screen.

.footer {position: absolute;bottom: 5vh;width: 100%;text-align: center;}

Here, the footer is positioned 5% of the viewport height up from the bottom edge.

Considerations and Potential Issues

While `vh` units are powerful, they come with a few considerations:

vh vs. vw

It's important to distinguish `vh` from `vw`. While `vh` is based on the viewport's height, `vw` is based on the viewport's width. Choosing between them depends on whether you want your element's size to be relative to the screen's height or width. For full-screen sections, `100vh` is typically used. For elements that should span the full width, `100vw` would be appropriate.

Conclusion

In summary, `vh` is a valuable CSS unit that represents a percentage of the viewport's height. It's instrumental in creating fluid and responsive web designs, allowing elements to scale proportionally with the browser window. By understanding its behavior and potential pitfalls, developers can effectively leverage `vh` to build modern, visually appealing, and adaptable web experiences.

Sources

  1. MDN Web Docs - CSS: Length - Viewport-relative lengthsCC-BY-SA-2.5
  2. W3C - CSS Values and Units Module Level 4W3C-LICENSE

Missing an answer?

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