Skip to main contentSkip to docs navigation

Width and height utilities for sizing elements relative to their parent or the viewport.

@layer utilities

Relative to the parent

Width utilities (w-25, w-50, w-75, w-100, w-auto) set the element's width as a percentage of its parent. Height utilities (h-25, h-50, h-75, h-100, h-auto) work the same way vertically. Additional values can be generated by modifying the $sizes Sass map.

Width 25%
Width 50%
Width 75%
Width 100%
Width auto
HTML
<div class="w-25 p-medium">Width 25%</div>
<div class="w-50 p-medium">Width 50%</div>
<div class="w-75 p-medium">Width 75%</div>
<div class="w-100 p-medium">Width 100%</div>
<div class="w-auto p-medium">Width auto</div>
Height 25%
Height 50%
Height 75%
Height 100%
Height auto
HTML
<div style="height: 100px;">
  <div class="h-25 d-inline-block" style="width: 19%;">Height 25%</div>
  <div class="h-50 d-inline-block" style="width: 19%;">Height 50%</div>
  <div class="h-75 d-inline-block" style="width: 19%;">Height 75%</div>
  <div class="h-100 d-inline-block" style="width: 19%;">Height 100%</div>
  <div class="h-auto d-inline-block" style="width: 19%;">Height auto</div>
</div>

mw-100 and mh-100 cap an element's width or height at 100% of its parent.

Max-width 100%
HTML
<div style="width: 50%; height: 100px;">
  <div class="mw-100" style="width: 200%;">Max-width 100%</div>
</div>
Max-height 100%
HTML
<div style="height: 100px;">
  <div class="mh-100" style="width: 100px; height: 200px;">Max-height 100%</div>
</div>

Relative to the viewport

Viewport-relative utilities set dimensions based on viewport units rather than the parent element.

HTML
<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>

CSS

Sizing utilities are generated via the utilities API.

Reference

The table lists all sizing utilities and their CSS properties.

ClassProperties
.w-2xsmallwidth: 1rem;
.w-xsmallwidth: 1.5rem;
.w-smallwidth: 2rem;
.w-mediumwidth: 2.5rem;
.w-largewidth: 3rem;
.w-xlargewidth: 3.5rem;
.w-2xlargewidth: 4rem;
.w-25width: 25%;
.w-50width: 50%;
.w-75width: 75%;
.w-100width: 100%;
.w-autowidth: auto;
.h-2xsmallheight: 1rem;
.h-xsmallheight: 1.5rem;
.h-smallheight: 2rem;
.h-mediumheight: 2.5rem;
.h-largeheight: 3rem;
.h-xlargeheight: 3.5rem;
.h-2xlargeheight: 4rem;
.h-25height: 25%;
.h-50height: 50%;
.h-75height: 75%;
.h-100height: 100%;
.h-autoheight: auto;
.min-w-2xsmallmin-width: 1rem;
.min-w-xsmallmin-width: 1.5rem;
.min-w-smallmin-width: 2rem;
.min-w-mediummin-width: 2.5rem;
.min-w-largemin-width: 3rem;
.min-w-xlargemin-width: 3.5rem;
.min-w-2xlargemin-width: 4rem;
.min-w-automin-width: auto;
.min-w-100min-width: 100%;
.min-h-2xsmallmin-height: 1rem;
.min-h-xsmallmin-height: 1.5rem;
.min-h-smallmin-height: 2rem;
.min-h-mediummin-height: 2.5rem;
.min-h-largemin-height: 3rem;
.min-h-xlargemin-height: 3.5rem;
.min-h-2xlargemin-height: 4rem;
.min-h-automin-height: auto;
.min-h-100min-height: 100%;
.max-w-2xsmallmax-width: 1rem;
.max-w-xsmallmax-width: 1.5rem;
.max-w-smallmax-width: 2rem;
.max-w-mediummax-width: 2.5rem;
.max-w-largemax-width: 3rem;
.max-w-xlargemax-width: 3.5rem;
.max-w-2xlargemax-width: 4rem;
.max-w-automax-width: auto;
.max-w-100max-width: 100%;
.max-h-2xsmallmax-height: 1rem;
.max-h-xsmallmax-height: 1.5rem;
.max-h-smallmax-height: 2rem;
.max-h-mediummax-height: 2.5rem;
.max-h-largemax-height: 3rem;
.max-h-xlargemax-height: 3.5rem;
.max-h-2xlargemax-height: 4rem;
.max-h-automax-height: auto;
.max-h-100max-height: 100%;
.vw-25width: 25vw;
.vw-50width: 50vw;
.vw-75width: 75vw;
.vw-100width: 100vw;
.vh-25height: 25vh;
.vh-50height: 50vh;
.vh-75height: 75vh;
.vh-100height: 100vh;
.min-vw-25min-width: 25vw;
.min-vw-50min-width: 50vw;
.min-vw-75min-width: 75vw;
.min-vw-100min-width: 100vw;
.min-vh-25min-height: 25vh;
.min-vh-50min-height: 50vh;
.min-vh-75min-height: 75vh;
.min-vh-100min-height: 100vh;

Utilities API

Sizing utilities are declared in scss/utilities/_sizing.scss using the utilities API.

"width": (
  property: width,
  class: w,
  values: map.merge(
    $sizes,
    (
      25: 25%,
      50: 50%,
      75: 75%,
      100: 100%,
      auto: auto
    )
  )
),
"height": (
  property: height,
  class: h,
  values: map.merge(
    $sizes,
    (
      25: 25%,
      50: 50%,
      75: 75%,
      100: 100%,
      auto: auto
    )
  )
),
"min-width": (
  property: min-width,
  class: min-w,
  values: map.merge($sizes, (auto: auto, 100: 100%))
),
"min-height": (
  property: min-height,
  class: min-h,
  values: map.merge($sizes, (auto: auto, 100: 100%))
),
"max-width": (
  property: max-width,
  class: max-w,
  values: map.merge($sizes, (auto: auto, 100: 100%))
),
"max-height": (
  property: max-height,
  class: max-h,
  values: map.merge($sizes, (auto: auto, 100: 100%))
),
"viewport-width": (
  property: width,
  class: vw,
  values: (
    25: 25vw,
    50: 50vw,
    75: 75vw,
    100: 100vw
  )
),
"viewport-height": (
  property: height,
  class: vh,
  values: (
    25: 25vh,
    50: 50vh,
    75: 75vh,
    100: 100vh
  )
),
"min-viewport-width": (
  property: min-width,
  class: min-vw,
  values: (
    25: 25vw,
    50: 50vw,
    75: 75vw,
    100: 100vw
  )
),
"min-viewport-height": (
  property: min-height,
  class: min-vh,
  values: (
    25: 25vh,
    50: 50vh,
    75: 75vh,
    100: 100vh
  )
),
"dynamic-viewport-height": (
  property: height,
  class: dvh,
  values: (
    25: 25dvh,
    50: 50dvh,
    75: 75dvh,
    100: 100dvh
  )
),