Sizing
Utilities for setting the width of an element.
Use w-{number}
or w-px
to set an element to a fixed width.
<div class="w-96 ..."></div>
<div class="w-80 ..."></div>
<div class="w-64 ..."></div>
<div class="w-48 ..."></div>
<div class="w-40 ..."></div>
<div class="w-32 ..."></div>
<div class="w-24 ..."></div>
Use w-{fraction}
or w-full
to set an element to a percentage based width.
<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>
Use w-screen
to make an element span the entire width of the viewport.
<div class="w-screen">
<!-- ... -->
</div>
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:
<div class="w-full md:w-auto">
<!-- ... -->
</div>
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.
<div class="w-1/2 hover:w-full">
<!-- ... -->
</div>
For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.
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.
<div class="w-1/2 md:w-full">
<!-- ... -->
</div>
To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.
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.
module.exports = {
theme: {
extend: {
spacing: {
'128': '32rem',
}
}
}
}
To customize width separately, use the theme.width
section of your tailwind.config.js
file.
module.exports = {
theme: {
extend: {
width: {
'128': '32rem',
}
}
}
}
Learn more about customizing the default theme in the theme customization documentation.
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.
<div class="w-[32rem]">
<!-- ... -->
</div>
Learn more about arbitrary value support in the arbitrary values documentation.