Skip to content

width

Utilities for setting the width of an element.

Quick reference

ClassStyles
w-<number>width: calc(var(--spacing) * <number>);
w-<fraction>width: calc(<fraction> * 100%);
w-3xswidth: var(--container-3xs); /* 16rem (256px) */
w-2xswidth: var(--container-2xs); /* 18rem (288px) */
w-xswidth: var(--container-xs); /* 20rem (320px) */
w-smwidth: var(--container-sm); /* 24rem (384px) */
w-mdwidth: var(--container-md); /* 28rem (448px) */
w-lgwidth: var(--container-lg); /* 32rem (512px) */
w-xlwidth: var(--container-xl); /* 36rem (576px) */
w-2xlwidth: var(--container-2xl); /* 42rem (672px) */
w-3xlwidth: var(--container-3xl); /* 48rem (768px) */
w-4xlwidth: var(--container-4xl); /* 56rem (896px) */
w-5xlwidth: var(--container-5xl); /* 64rem (1024px) */
w-6xlwidth: var(--container-6xl); /* 72rem (1152px) */
w-7xlwidth: var(--container-7xl); /* 80rem (1280px) */
w-autowidth: auto;
w-pxwidth: 1px;
w-fullwidth: 100%;
w-screenwidth: 100vw;
w-dvwwidth: 100dvw;
w-dvhwidth: 100dvh;
w-lvwwidth: 100lvw;
w-lvhwidth: 100lvh;
w-svwwidth: 100svw;
w-svhwidth: 100svh;
w-minwidth: min-content;
w-maxwidth: max-content;
w-fitwidth: fit-content;
w-(<custom-property>)width: var(<custom-property>);
w-[<value>]width: <value>;
size-<number>width: calc(var(--spacing) * <number>); height: calc(var(--spacing) * <number>);
size-<fraction>width: calc(<fraction> * 100%); height: calc(<fraction> * 100%);
size-autowidth: auto; height: auto;
size-pxwidth: 1px; height: 1px;
size-fullwidth: 100%; height: 100%;
size-dvwwidth: 100dvw; height: 100dvw;
size-dvhwidth: 100dvh; height: 100dvh;
size-lvwwidth: 100lvw; height: 100lvw;
size-lvhwidth: 100lvh; height: 100lvh;
size-svwwidth: 100svw; height: 100svw;
size-svhwidth: 100svh; height: 100svh;
size-minwidth: min-content; height: min-content;
size-maxwidth: max-content; height: max-content;
size-fitwidth: fit-content; height: fit-content;
size-(<custom-property>)width: var(<custom-property>); height: var(<custom-property>);
size-[<value>]width: <value>; height: <value>;

Source: https://tailwindcss.com/guide/width

Examples

Basic example

Use w-<number> utilities like w-24 and w-64 to set an element to a fixed width based on the spacing scale:

html
<!-- [!code classes:w-96,w-80,w-64,w-48,w-40,w-32,w-24] -->
<div class="w-96 ...">w-96</div>
<div class="w-80 ...">w-80</div>
<div class="w-64 ...">w-64</div>
<div class="w-48 ...">w-48</div>
<div class="w-40 ...">w-40</div>
<div class="w-32 ...">w-32</div>
<div class="w-24 ...">w-24</div>

Using a percentage

Use w-full or w-&lt;fraction&gt; utilities like w-1/2 and w-2/5 to give an element a percentage-based width:

html
<!-- [!code classes:w-1/2,w-2/5,w-3/5,w-1/3,w-2/3,w-1/4,w-3/4,w-1/5,w-4/5,w-1/6,w-5/6,w-full] -->
<div class="flex ...">
  <div class="w-1/2 ...">w-1/2</div>
  <div class="w-1/2 ...">w-1/2</div>
</div>
<div class="flex ...">
  <div class="w-2/5 ...">w-2/5</div>
  <div class="w-3/5 ...">w-3/5</div>
</div>
<div class="flex ...">
  <div class="w-1/3 ...">w-1/3</div>
  <div class="w-2/3 ...">w-2/3</div>
</div>
<div class="flex ...">
  <div class="w-1/4 ...">w-1/4</div>
  <div class="w-3/4 ...">w-3/4</div>
</div>
<div class="flex ...">
  <div class="w-1/5 ...">w-1/5</div>
  <div class="w-4/5 ...">w-4/5</div>
</div>
<div class="flex ...">
  <div class="w-1/6 ...">w-1/6</div>
  <div class="w-5/6 ...">w-5/6</div>
</div>
<div class="w-full ...">w-full</div>

Using the container scale

Use utilities like w-sm and w-xl to set an element to a fixed width based on the container scale:

html
<!-- [!code classes:w-xl,w-lg,w-md,w-sm,w-xs,w-2xs,w-3xs] -->
<div class="w-xl ...">w-xl</div>
<div class="w-lg ...">w-lg</div>
<div class="w-md ...">w-md</div>
<div class="w-sm ...">w-sm</div>
<div class="w-xs ...">w-xs</div>
<div class="w-2xs ...">w-2xs</div>
<div class="w-3xs ...">w-3xs</div>

Matching the viewport

Use the w-screen utility to make an element span the entire width of the viewport:

html
<!-- [!code classes:w-screen] -->
<div class="w-screen">
  <!-- ... -->
</div>

Alternatively, you can match the width of the large, small or dynamic viewports using the w-lvw, w-svw, and w-dvw utilities.

Resetting the width

Use the w-auto utility to remove an element's assigned width under a specific condition, like at a particular breakpoint:

html
<!-- [!code classes:w-full,w-auto] -->
<div class="w-full md:w-auto">
  <!-- ... -->
</div>

Setting both width and height

Use utilities like size-px, size-4, and size-full to set both the width and height of an element at the same time:

html
<!-- [!code classes:size-16,size-20,size-24,size-32,size-40] -->
<div class="size-16 ...">size-16</div>
<div class="size-20 ...">size-20</div>
<div class="size-24 ...">size-24</div>
<div class="size-32 ...">size-32</div>
<div class="size-40 ...">size-40</div>

Using a custom value

Use the w-[&lt;value&gt;] syntax to set the width based on a completely custom value:

html
<div class="w-[5px] ...">
  <!-- ... -->
</div>

For CSS variables, you can also use the w-(&lt;custom-property&gt;) syntax:

html
<div class="w-(--my-width) ...">
  <!-- ... -->
</div>

This is just a shorthand for w-[var(&lt;custom-property&gt;)] that adds the var() function for you automatically.

Responsive design

Prefix a width utility with a breakpoint variant like md: to only apply the utility at medium screen sizes and above:

html
<div class="w-1/2 md:w-full ...">
  <!-- ... -->
</div>

Learn more about using variants in the variants documentation.

Customizing your theme

The w-&lt;number&gt; and size-&lt;number&gt; utilities are driven by the --spacing theme variable, which can be customized in your own theme:

css
@theme {
  --spacing: 1px;
}

Learn more about customizing the spacing scale in the theme variable documentation.

Released under the MIT License.