Utilities for setting the width of an element
Use w-auto
to let the browser calculate and select the width for the element. You can use it to unset a specific width:
<div class="w-24 md:w-auto ..."></div>
Use w-screen
to make an element span the entire width of the viewport.
<div class="h-12 w-screen"></div>
Use w-{number}
or w-px
to set an element to a fixed width.
w-8
w-12
w-16
w-24
<div>
<div class="w-8 ..."></div>
<div class="w-12 ..."></div>
<div class="w-16 ..."></div>
<div class="w-24 ..."></div>
</div>
<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>
To control the width of an element at a specific breakpoint, add a {screen}:
prefix to any existing width utility. For example, adding the class md:w-full
to an element would apply the w-full
utility at medium screen sizes and above.
<div class="w-1/2 md:w-full ...">
<!-- ... -->
</div>
For more information about Tailwind’s responsive design features, check out the Responsive Design documentation.
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 the spacing scale for padding, margin, width, and height all at once in the theme.spacing
or theme.extend.spacing
sections of your tailwind.config.js
file:
// tailwind.config.js
module.exports = {
theme: {
extend: {
+ spacing: {
+ '72': '18rem',
+ '84': '21rem',
+ '96': '24rem',
+ }
}
}
}
To customize width separately, use the theme.width
section of your tailwind.config.js
file.
// tailwind.config.js
module.exports = {
theme: {
extend: {
+ width: {
+ '1/7': '14.2857143%',
+ '2/7': '28.5714286%',
+ '3/7': '42.8571429%',
+ '4/7': '57.1428571%',
+ '5/7': '71.4285714%',
+ '6/7': '85.7142857%',
+ }
}
}
}
Learn more about customizing the default theme in the theme customization documentation.
By default, only responsive variants are generated for width utilities.
You can control which variants are generated for the width utilities by modifying the width
property in the variants
section of your tailwind.config.js
file.
For example, this config will also generate hover and focus variants:
// tailwind.config.js
module.exports = {
variants: {
extend: {
// ...
+ width: ['hover', 'focus'],
}
}
}
If you don't plan to use the width utilities in your project, you can disable them entirely by setting the width
property to false
in the corePlugins
section of your config file:
// tailwind.config.js
module.exports = {
corePlugins: {
// ...
+ width: false,
}
}