Bootstrap CSS Sizing Utilities: Creating Responsive Layouts with Percentage-Based Width and Height

Learn how to use Bootstrap's CSS sizing utilities to easily control the width and height of elements using percentage-based classes. This tutorial explains how these utilities simplify responsive design, allowing you to create layouts that adapt seamlessly to different screen sizes.



CSS Sizing Utilities

These CSS utilities provide a quick way to set the width and height of elements relative to their parent container. This is helpful for creating responsive layouts that adapt to different screen sizes.

Sizing with Width and Height

You can easily control element size using width and height utilities. Bootstrap provides classes for common percentages (25%, 50%, 75%, 100%). These are generated from Sass variables, so you can easily customize them if needed.

Width Utilities

Use these classes to set an element's width as a percentage of its parent:

  • .w-25: 25% width
  • .w-50: 50% width
  • .w-75: 75% width
  • .w-100: 100% width

Height Utilities

Similar classes are used for height:

  • .h-25: 25% height
  • .h-50: 50% height
  • .h-75: 75% height
  • .h-100: 100% height

Setting Maximum Width and Height

To set maximum width or height, use the `max-width` and `max-height` properties. This ensures that an element does not exceed a specific size but allows it to be smaller if its content requires less space.

Maximum Width


max-width: 100%; 

Maximum Height


max-height: 100%;