Sizing: Width, Height & Viewport Utilities

Bootstrap Framework 7 min min read Updated: Nov 16, 2026 Beginner
Sizing: Width, Height & Viewport Utilities
Beginner Topic 5 of 11

Width and Height Classes

You can set the width or height of an element as a percentage of its parent using simple classes.

ClassResult
w-25width: 25%
w-50width: 50%
w-75width: 75%
w-100width: 100%
w-autowidth: auto
h-25 to h-100Same options for height (parent needs a height)

Example

html <div class="w-25 p-3 bg-primary text-white mb-2">Width 25%</div> <div class="w-50 p-3 bg-success text-white mb-2">Width 50%</div> <div class="w-100 p-3 bg-danger text-white">Width 100%</div>
Result

Three colored bars of different lengths: a quarter, half and the full width of their parent.

Height

Percentage heights only work when the parent element has a defined height.

html <div style="height: 200px;" class="bg-light"> <div class="h-50 bg-info">Half height</div> </div>

Max Width and Max Height

html <img src="photo.jpg" class="mw-100" alt="Photo"> <div class="mh-100">Max height 100%</div>

Viewport Units

The viewport is the visible area of the browser window. Use these classes to size elements based on the screen itself:

ClassMeaning
vw-100100% of the viewport width
vh-100100% of the viewport height
min-vw-100Minimum width of the viewport width
min-vh-100Minimum height of the viewport height
html <section class="vh-100 d-flex align-items-center justify-content-center bg-dark text-white"> <h1>Full Screen Hero</h1> </section>

This makes a hero section that exactly fills the screen, with the heading centered.

Responsive Images with Sizing

For images, img-fluid (a later lesson) is usually better than w-100, because it never makes the image bigger than its natural size.

Conclusion

Sizing utilities help you control element dimensions in a quick and readable way. For full screen sections, vh-100 is your best friend.

Quick Summary: w-25/50/75/100 and h-25/50/75/100 use percentages, mw-100 limits width, and vh-100 fills the screen height.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators