Sizing
Width and height utilities for sizing elements relative to their parent or the viewport.
On this page
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
<div class="w-25 p-md">Width 25%</div>
<div class="w-50 p-md">Width 50%</div>
<div class="w-75 p-md">Width 75%</div>
<div class="w-100 p-md">Width 100%</div>
<div class="w-auto p-md">Width auto</div>Height 25%
Height 50%
Height 75%
Height 100%
Height auto
<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%
<div style="width: 50%; height: 100px;">
<div class="mw-100" style="width: 200%;">Max-width 100%</div>
</div>Max-height 100%
<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.
<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.
| Class | Properties |
|---|---|
.w-2xs | width: 1rem; |
.w-xs | width: 1.5rem; |
.w-sm | width: 2rem; |
.w-md | width: 2.5rem; |
.w-lg | width: 3rem; |
.w-xl | width: 3.5rem; |
.w-2xl | width: 4rem; |
.w-25 | width: 25%; |
.w-50 | width: 50%; |
.w-75 | width: 75%; |
.w-100 | width: 100%; |
.w-auto | width: auto; |
.h-2xs | height: 1rem; |
.h-xs | height: 1.5rem; |
.h-sm | height: 2rem; |
.h-md | height: 2.5rem; |
.h-lg | height: 3rem; |
.h-xl | height: 3.5rem; |
.h-2xl | height: 4rem; |
.h-25 | height: 25%; |
.h-50 | height: 50%; |
.h-75 | height: 75%; |
.h-100 | height: 100%; |
.h-auto | height: auto; |
.min-w-2xs | min-width: 1rem; |
.min-w-xs | min-width: 1.5rem; |
.min-w-sm | min-width: 2rem; |
.min-w-md | min-width: 2.5rem; |
.min-w-lg | min-width: 3rem; |
.min-w-xl | min-width: 3.5rem; |
.min-w-2xl | min-width: 4rem; |
.min-w-auto | min-width: auto; |
.min-w-100 | min-width: 100%; |
.min-h-2xs | min-height: 1rem; |
.min-h-xs | min-height: 1.5rem; |
.min-h-sm | min-height: 2rem; |
.min-h-md | min-height: 2.5rem; |
.min-h-lg | min-height: 3rem; |
.min-h-xl | min-height: 3.5rem; |
.min-h-2xl | min-height: 4rem; |
.min-h-auto | min-height: auto; |
.min-h-100 | min-height: 100%; |
.max-w-2xs | max-width: 1rem; |
.max-w-xs | max-width: 1.5rem; |
.max-w-sm | max-width: 2rem; |
.max-w-md | max-width: 2.5rem; |
.max-w-lg | max-width: 3rem; |
.max-w-xl | max-width: 3.5rem; |
.max-w-2xl | max-width: 4rem; |
.max-w-auto | max-width: auto; |
.max-w-100 | max-width: 100%; |
.max-h-2xs | max-height: 1rem; |
.max-h-xs | max-height: 1.5rem; |
.max-h-sm | max-height: 2rem; |
.max-h-md | max-height: 2.5rem; |
.max-h-lg | max-height: 3rem; |
.max-h-xl | max-height: 3.5rem; |
.max-h-2xl | max-height: 4rem; |
.max-h-auto | max-height: auto; |
.max-h-100 | max-height: 100%; |
.vw-25 | width: 25vw; |
.vw-50 | width: 50vw; |
.vw-75 | width: 75vw; |
.vw-100 | width: 100vw; |
.vh-25 | height: 25vh; |
.vh-50 | height: 50vh; |
.vh-75 | height: 75vh; |
.vh-100 | height: 100vh; |
.min-vw-25 | min-width: 25vw; |
.min-vw-50 | min-width: 50vw; |
.min-vw-75 | min-width: 75vw; |
.min-vw-100 | min-width: 100vw; |
.min-vh-25 | min-height: 25vh; |
.min-vh-50 | min-height: 50vh; |
.min-vh-75 | min-height: 75vh; |
.min-vh-100 | min-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
)
),