What if you could resize elements instantly just by changing a class name?
Why Sizing utilities (width, height) in Bootsrap? - Purpose & Use Cases
Imagine you want to make a box exactly 200 pixels wide and 100 pixels tall on your webpage. You write CSS rules for width and height manually for each box.
When you need to change sizes for many boxes, you must update each CSS rule separately. This takes time and can cause mistakes, especially if you want consistent sizes across your site.
Bootstrap's sizing utilities let you quickly apply standard widths and heights using simple classes. You just add a class like w-50 or h-25 to your element, and it gets the right size instantly.
.box { width: 200px; height: 100px; }
<div class="box">Content</div><div class="w-50 h-25">Content</div>
You can easily keep sizes consistent and change them fast by just swapping classes, without touching CSS files.
On a product page, you want all product images to have the same width and height. Using sizing utilities, you add classes to images so they all look uniform and responsive.
Manually setting sizes is slow and error-prone.
Sizing utilities provide ready-made classes for width and height.
They make your design consistent and easy to update.
Practice
Solution
Step 1: Understand width and height prefixes
Bootstrap usesw-for width andh-for height classes.Step 2: Identify the class for 50% width
The classw-50sets width to 50%, whileh-50sets height to 50%.Final Answer:
<code>w-50</code> -> Option AQuick Check:
Width 50% = w-50 [OK]
- Confusing width (w-) with height (h-)
- Using w-100 instead of w-50
- Assuming h-50 sets width
Solution
Step 1: Recall Bootstrap height classes
Bootstrap usesh-100to set height to 100% of the parent container.Step 2: Viewport height in Bootstrap
Bootstrap does not have a classvh-100to set height to 100vh. To set height to viewport height, custom CSS or utility classes are needed.Final Answer:
<code>h-100</code> -> Option BQuick Check:
Height 100% of parent = h-100 [OK]
- Using h-vh-100 or h-100vh which are invalid
- Assuming vh-100 is a Bootstrap class
- Confusing viewport height with parent height
<div class='w-75'></div> element relative to its parent container?Solution
Step 1: Understand the meaning of w-75
The classw-75sets the element's width to 75% of its parent container.Step 2: Compare options with the class effect
Only 75% of the parent container correctly states 75% width relative to the parent.Final Answer:
75% of the parent container -> Option DQuick Check:
w-75 means width 75% [OK]
- Mixing up 75% with 25%
- Thinking w-75 means height
- Assuming w-75 means 100% width
<div class='w-25'></div> does not work as expected. What is the error?Solution
Step 1: Identify the class used
The classw-25sets width to 25%, not height.Step 2: Correct the class for height
To set height to 25%, useh-25instead ofw-25.Final Answer:
Using width classw-25instead of height classh-25-> Option AQuick Check:
Height needs h-25, not w-25 [OK]
- Confusing width and height classes
- Assuming w-25 affects height
- Thinking Bootstrap lacks height utilities
Solution
Step 1: Understand responsive sizing classes
Bootstrap uses breakpoint prefixes likemdto apply styles at medium screen sizes and above.Step 2: Choose classes for width at different breakpoints
w-100sets width 100% on all screens, butw-md-50overrides width to 50% on medium and larger screens.Step 3: Verify other options
Options B, C, and D either reverse the sizes or mix height and width incorrectly.Final Answer:
<code>w-100 w-md-50</code> -> Option CQuick Check:
Responsive width: w-100 then w-md-50 [OK]
- Mixing height and width classes
- Reversing breakpoint order
- Not using breakpoint prefixes for responsiveness
Ready to prove it?
Pass the test and this pattern moves unknown
