Skip to main content

Utilities

Sizing

Easily make an element as wide or as tall as you want with our width and height utilities.

Relative to the parent

Width and height utilities are generated from the utility API in _utilities.scss. Includes support for 25%, 50%, 75%, 100%, and auto by default. Modify those values as you need to generate different utilities here.

Width 25%
Width 50%
Width 75%
Width 100%
Width auto
HTML
<div class="w-25 p-3 bg-body-tertiary border">Width 25%</div>
<div class="w-50 p-3 bg-body-tertiary border">Width 50%</div>
<div class="w-75 p-3 bg-body-tertiary border">Width 75%</div>
<div class="w-100 p-3 bg-body-tertiary border">Width 100%</div>
<div class="w-auto p-3 bg-body-tertiary border">Width auto</div>
Height 25%
Height 50%
Height 75%
Height 100%
Height auto
HTML
<div style="height: 100px" class="bg-body-tertiary border">
  <div class="h-25 d-inline-block text-bg-navy" style="width: 120px">Height 25%</div>
  <div class="h-50 d-inline-block text-bg-navy" style="width: 120px">Height 50%</div>
  <div class="h-75 d-inline-block text-bg-navy" style="width: 120px">Height 75%</div>
  <div class="h-100 d-inline-block text-bg-navy" style="width: 120px">Height 100%</div>
  <div class="h-auto d-inline-block text-bg-navy" style="width: 120px">Height auto</div>
</div>

You can also use max-width: 100%; and max-height: 100%; utilities as needed.

1200 px wide, but .mw-100 keeps it inside the box
HTML
<svg class="mw-100 border rounded" width="1200" height="100" viewBox="0 0 1200 100" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Placeholder: 1200 wide image constrained by .mw-100"><rect width="1200" height="100" fill="var(--bs-navy-500)"/><text x="600" y="56" fill="var(--bs-cream-50)" text-anchor="middle" font-size="18">1200 px wide, but .mw-100 keeps it inside the box</text></svg>
Max-height 100%
HTML
<div style="height: 100px" class="bg-body-tertiary border">
  <div class="mh-100 text-bg-navy" style="width: 120px; height: 200px">Max-height 100%</div>
</div>

The full list:

WidthHeightValue
.w-25.h-2525%
.w-50.h-5050%
.w-75.h-7575%
.w-100.h-100100%
.w-auto.h-autoauto
.mw-100.mh-100max 100%
Height percentages only resolve when the parent has an explicit height. In a flex column, use .flex-fill or .flex-grow-1 instead — see Flex.

Relative to the viewport

You can also use utilities to set the width and height relative to the viewport.

<div class="min-vw-100">Min-width 100vw</div>
<div class="min-vh-100">Min-height 100vh</div>
<div class="vw-100">Width 100vw</div>
<div class="vh-100">Height 100vh</div>
ClassRule
.vw-100width: 100vw
.vh-100height: 100vh
.min-vw-100min-width: 100vw
.min-vh-100min-height: 100vh

The docs layout itself uses min-height: 100vh on the body so the footer never floats mid-screen on a short page. .vw-100 includes the vertical scrollbar's width on desktop, so it can cause a horizontal scrollbar; prefer .w-100 on a full-width parent.

Fixed widths

There are no fixed-pixel width utilities. For a sidebar or an avatar, set the width in your own CSS or use the grid columns. For spacing-sized boxes the spacing scale values (--space-1 … --space-8) are the right vocabulary:

.avatar { width: var(--space-8); height: var(--space-8); } /* 4rem */

CSS

"width": (
  property: width,
  class: w,
  values: (25: 25%, 50: 50%, 75: 75%, 100: 100%, auto: auto)
),
"max-width": (property: max-width, class: mw, values: (100: 100%)),
"viewport-width": (property: width, class: vw, values: (100: 100vw)),
"min-viewport-width": (property: min-width, class: min-vw, values: (100: 100vw)),
"height": (
  property: height,
  class: h,
  values: (25: 25%, 50: 50%, 75: 75%, 100: 100%, auto: auto)
),
"max-height": (property: max-height, class: mh, values: (100: 100%)),
"viewport-height": (property: height, class: vh, values: (100: 100vh)),
"min-viewport-height": (property: min-height, class: min-vh, values: (100: 100vh)),