Skip to main contentSkip to docs navigation

Chassis

Set the width and height of an element relative to its parent or the viewport, with responsive fraction widths.

@layer utilities

Relative to the parent

Width utilities (.w-25, .w-50, .w-75, .w-100, .w-auto) set the width of an element as a percentage of its parent. Height utilities (.h-25, .h-50, .h-75, .h-100, .h-auto) do the same for the height. The keys of the $sizes Sass map add a class per named size, such as .w-md.

Width 25%
Width 50%
Width 75%
Width 100%
Width auto
HTML
<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
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>

.max-w-100 and .max-h-100 cap the width or height of an element 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>

Fractions

.w-{n}/12 sets the width to n twelfths of the parent, from .w-1/12 to .w-11/12. Unlike .w-25, .w-50 and .w-75, the fractions have a variant per breakpoint (.md:w-6/12), which sizes an element responsively outside a grid: an image beside floated text, a skeleton line, the image of a horizontal card.

.w-4/12
.w-8/12
.w-100 .md:w-6/12
HTML
<div class="w-4/12 p-md mb-xs">.w-4/12</div>
<div class="w-8/12 p-md mb-xs">.w-8/12</div>
<div class="w-100 md:w-6/12 p-md">.w-100 .md:w-6/12</div>

.w-100 and .w-auto have a variant per breakpoint too, which ends a fraction at a breakpoint: .w-6/12 .lg:w-auto is half of the parent below lg and back to its default width from lg up, and .md:w-100 returns an element to the full width.

.w-6/12 .lg:w-auto
.w-8/12 .md:w-100
HTML
<div class="w-6/12 lg:w-auto p-md mb-xs">.w-6/12 .lg:w-auto</div>
<div class="w-8/12 md:w-100 p-md">.w-8/12 .md:w-100</div>

The fractions, .w-100, and .w-auto also have a variant per container width, under the @ prefix: .@md:w-6/12 applies when the nearest query container is at least as wide as the md breakpoint.

The names and values are those of the Tailwind fraction widths: .w-6/12 declares width: calc(6 / 12 * 100%). In a stylesheet the slash is escaped (.w-6\/12); in HTML the class is written as is.

A flex item with a fraction width still shrinks. Add .flex-shrink-0 to keep the width when siblings need the room.

Relative to the viewport

Viewport-relative utilities set the width and height in viewport units instead of percentages of the parent.

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-2xswidth: 1rem;
.w-xswidth: 1.5rem;
.w-smwidth: 2rem;
.w-mdwidth: 2.5rem;
.w-lgwidth: 3rem;
.w-xlwidth: 3.5rem;
.w-2xlwidth: 4rem;
.w-25width: 25%;
.w-50width: 50%;
.w-75width: 75%;
.w-1/12width: calc(1 / 12 * 100%);
.w-2/12width: calc(2 / 12 * 100%);
.w-3/12width: calc(3 / 12 * 100%);
.w-4/12width: calc(4 / 12 * 100%);
.w-5/12width: calc(5 / 12 * 100%);
.w-6/12width: calc(6 / 12 * 100%);
.w-7/12width: calc(7 / 12 * 100%);
.w-8/12width: calc(8 / 12 * 100%);
.w-9/12width: calc(9 / 12 * 100%);
.w-10/12width: calc(10 / 12 * 100%);
.w-11/12width: calc(11 / 12 * 100%);
.w-100width: 100%;
.w-autowidth: auto;
.h-2xsheight: 1rem;
.h-xsheight: 1.5rem;
.h-smheight: 2rem;
.h-mdheight: 2.5rem;
.h-lgheight: 3rem;
.h-xlheight: 3.5rem;
.h-2xlheight: 4rem;
.h-25height: 25%;
.h-50height: 50%;
.h-75height: 75%;
.h-100height: 100%;
.h-autoheight: auto;
.min-w-2xsmin-width: 1rem;
.min-w-xsmin-width: 1.5rem;
.min-w-smmin-width: 2rem;
.min-w-mdmin-width: 2.5rem;
.min-w-lgmin-width: 3rem;
.min-w-xlmin-width: 3.5rem;
.min-w-2xlmin-width: 4rem;
.min-w-automin-width: auto;
.min-w-100min-width: 100%;
.min-h-2xsmin-height: 1rem;
.min-h-xsmin-height: 1.5rem;
.min-h-smmin-height: 2rem;
.min-h-mdmin-height: 2.5rem;
.min-h-lgmin-height: 3rem;
.min-h-xlmin-height: 3.5rem;
.min-h-2xlmin-height: 4rem;
.min-h-automin-height: auto;
.min-h-100min-height: 100%;
.max-w-2xsmax-width: 1rem;
.max-w-xsmax-width: 1.5rem;
.max-w-smmax-width: 2rem;
.max-w-mdmax-width: 2.5rem;
.max-w-lgmax-width: 3rem;
.max-w-xlmax-width: 3.5rem;
.max-w-2xlmax-width: 4rem;
.max-w-automax-width: auto;
.max-w-100max-width: 100%;
.max-h-2xsmax-height: 1rem;
.max-h-xsmax-height: 1.5rem;
.max-h-smmax-height: 2rem;
.max-h-mdmax-height: 2.5rem;
.max-h-lgmax-height: 3rem;
.max-h-xlmax-height: 3.5rem;
.max-h-2xlmax-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;

Sass maps

$sizes in scss/maps/_sizing.scss holds the named sizes of the width, height, and min and max utilities.

$sizes: (
  2xs:              $size-2xsmall,
  xs:               $size-xsmall,
  sm:               $size-small,
  md:               $size-medium,
  lg:               $size-large,
  xl:               $size-xlarge,
  2xl:              $size-2xlarge,
);

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%
    )
  )
),
// The widths with a variant per breakpoint: the fractions, and `w-100` and
// `w-auto`, which reset a fraction at a breakpoint (`w-6/12 lg:w-auto`).
"width-fraction": (
  responsive: true,
  container: true,
  property: width,
  class: w,
  values: map.merge(
    $-width-fractions,
    (
      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
  )
),