100vh Bootstrap 5

4 min read Jun 24, 2024
100vh Bootstrap 5

Understanding 100vh in Bootstrap 5

When working with Bootstrap 5, you may have encountered the term "100vh" in various documentation and examples. But what does it mean, and how does it impact your web development projects?

What is 100vh?

100vh is a CSS unit that stands for "100 viewport height." It's a relative unit that represents the height of the viewport, which is the visible area of the web page. In other words, 100vh is equivalent to the full height of the browser window.

How does it work in Bootstrap 5?

In Bootstrap 5, 100vh is used to set the height of an element to the full height of the viewport. This can be useful for creating full-screen backgrounds, hero sections, or other elements that need to occupy the entire height of the screen.

To use 100vh in Bootstrap 5, you can add the h-100 class to an element, like this:

This will set the height of the element to 100% of the viewport height, making it full-screen.

Advantages of using 100vh

  1. Responsive design: 100vh is a responsive unit, which means it adapts to different screen sizes and devices. This makes it ideal for creating responsive web designs.
  2. Easy to use: Adding the h-100 class is a simple way to make an element full-screen, without having to write custom CSS code.
  3. Flexibility: 100vh can be used in conjunction with other Bootstrap classes, such as w-100 to create full-screen elements with custom widths.

Common use cases for 100vh

  1. Hero sections: Use 100vh to create full-screen hero sections with background images or videos.
  2. Full-screen modals: Add h-100 to a modal container to make it full-screen.
  3. Background images: Use 100vh to set the height of a background image to the full height of the viewport.

Conclusion

In conclusion, 100vh is a powerful CSS unit that can be used to create full-screen elements in Bootstrap 5. By adding the h-100 class to an element, you can easily set its height to the full height of the viewport, making it ideal for various web development projects.

Related Post


Featured Posts