Sizing

Width

Utilities for setting the width of an element.

Quick reference

Class
Properties
w-0width: 0px;
w-pxwidth: 1px;
w-0.5width: 0.125rem; / 2px /
w-1width: 0.25rem; / 4px /
w-1.5width: 0.375rem; / 6px /
w-2width: 0.5rem; / 8px /
w-2.5width: 0.625rem; / 10px /
w-3width: 0.75rem; / 12px /
w-3.5width: 0.875rem; / 14px /
w-4width: 1rem; / 16px /
w-5width: 1.25rem; / 20px /
w-6width: 1.5rem; / 24px /
w-7width: 1.75rem; / 28px /
w-8width: 2rem; / 32px /
w-9width: 2.25rem; / 36px /
w-10width: 2.5rem; / 40px /
w-11width: 2.75rem; / 44px /
w-12width: 3rem; / 48px /
w-14width: 3.5rem; / 56px /
w-16width: 4rem; / 64px /
w-20width: 5rem; / 80px /
w-24width: 6rem; / 96px /
w-28width: 7rem; / 112px /
w-32width: 8rem; / 128px /
w-36width: 9rem; / 144px /
w-40width: 10rem; / 160px /
w-44width: 11rem; / 176px /
w-48width: 12rem; / 192px /
w-52width: 13rem; / 208px /
w-56width: 14rem; / 224px /
w-60width: 15rem; / 240px /
w-64width: 16rem; / 256px /
w-72width: 18rem; / 288px /
w-80width: 20rem; / 320px /
w-96width: 24rem; / 384px /
w-autowidth: auto;
w-1/2width: 50%;
w-1/3width: 33.333333%;
w-2/3width: 66.666667%;
w-1/4width: 25%;
w-2/4width: 50%;
w-3/4width: 75%;
w-1/5width: 20%;
w-2/5width: 40%;
w-3/5width: 60%;
w-4/5width: 80%;
w-1/6width: 16.666667%;
w-2/6width: 33.333333%;
w-3/6width: 50%;
w-4/6width: 66.666667%;
w-5/6width: 83.333333%;
w-1/12width: 8.333333%;
w-2/12width: 16.666667%;
w-3/12width: 25%;
w-4/12width: 33.333333%;
w-5/12width: 41.666667%;
w-6/12width: 50%;
w-7/12width: 58.333333%;
w-8/12width: 66.666667%;
w-9/12width: 75%;
w-10/12width: 83.333333%;
w-11/12width: 91.666667%;
w-fullwidth: 100%;
w-screenwidth: 100vw;
w-minwidth: min-content;
w-maxwidth: max-content;
w-fitwidth: fit-content;

Show all classes

Basic usage

Fixed widths

Use w-{number} or w-px to set an element to a fixed width.

Width - 图1

  1. <div class="w-96 ..."></div>
  2. <div class="w-80 ..."></div>
  3. <div class="w-64 ..."></div>
  4. <div class="w-48 ..."></div>
  5. <div class="w-40 ..."></div>
  6. <div class="w-32 ..."></div>
  7. <div class="w-24 ..."></div>

Percentage widths

Use w-{fraction} or w-full to set an element to a percentage based width.

Width - 图2

  1. <div class="flex ...">
  2. <div class="w-1/2 ... ">w-1/2</div>
  3. <div class="w-1/2 ... ">w-1/2</div>
  4. </div>
  5. <div class="flex ...">
  6. <div class="w-2/5 ...">w-2/5</div>
  7. <div class="w-3/5 ...">w-3/5</div>
  8. </div>
  9. <div class="flex ...">
  10. <div class="w-1/3 ...">w-1/3</div>
  11. <div class="w-2/3 ...">w-2/3</div>
  12. </div>
  13. <div class="flex ...">
  14. <div class="w-1/4 ...">w-1/4</div>
  15. <div class="w-3/4 ...">w-3/4</div>
  16. </div>
  17. <div class="flex ...">
  18. <div class="w-1/5 ...">w-1/5</div>
  19. <div class="w-4/5 ...">w-4/5</div>
  20. </div>
  21. <div class="flex ...">
  22. <div class="w-1/6 ...">w-1/6</div>
  23. <div class="w-5/6 ...">w-5/6</div>
  24. </div>
  25. <div class="w-full ...">w-full</div>

Viewport width

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

  1. <div class="w-screen">
  2. <!-- ... -->
  3. </div>

Resetting the width

The w-auto utility can be useful if you need to remove an element’s assigned width under a specific condition, like at a particular breakpoint:

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

Applying conditionally

Hover, focus, and other states

Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:w-full to only apply the w-full utility on hover.

  1. <div class="w-1/2 hover:w-full">
  2. <!-- ... -->
  3. </div>

For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.

Breakpoints and media queries

You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:w-full to apply the w-full utility at only medium screen sizes and above.

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

To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.


Using custom values

Customizing your theme

By default, Tailwind’s width scale is a combination of the default spacing scale as well as some additional values specific to widths.

You can customize your spacing scale by editing theme.spacing or theme.extend.spacing in your tailwind.config.js file.

tailwind.config.js

  1. module.exports = {
  2. theme: {
  3. extend: {
  4. spacing: {
  5. '128': '32rem',
  6. }
  7. }
  8. }
  9. }

To customize width separately, use the theme.width section of your tailwind.config.js file.

tailwind.config.js

  1. module.exports = {
  2. theme: {
  3. extend: {
  4. width: {
  5. '128': '32rem',
  6. }
  7. }
  8. }
  9. }

Learn more about customizing the default theme in the theme customization documentation.

Arbitrary values

If you need to use a one-off width value that doesn’t make sense to include in your theme, use square brackets to generate a property on the fly using any arbitrary value.

  1. <div class="w-[32rem]">
  2. <!-- ... -->
  3. </div>

Learn more about arbitrary value support in the arbitrary values documentation.