Utilities for controlling how flex items both grow and shrink.
Use flex-initial
to allow a flex item to shrink but not grow, taking into account its initial size:
Items don't grow when there's extra space
Items shrink if possible when needed
<div class="flex">
<div class="flex-initial ...">
<!-- Won't grow, but will shrink if needed -->
</div>
<div class="flex-initial ...">
<!-- Won't grow, but will shrink if needed -->
</div>
<div class="flex-initial ...">
<!-- Won't grow, but will shrink if needed -->
</div>
</div>
Default behavior
With .flex-1
<div class="flex">
<div class="flex-1 ...">
<!-- Will grow and shrink as needed without taking initial size into account -->
</div>
<div class="flex-1 ...">
<!-- Will grow and shrink as needed without taking initial size into account -->
</div>
<div class="flex-1 ...">
<!-- Will grow and shrink as needed without taking initial size into account -->
</div>
</div>
Default behavior
With .flex-auto
<div class="flex ...">
<div class="flex-auto ...">
<!-- Will grow and shrink as needed taking initial size into account -->
</div>
<div class="flex-auto ...">
<!-- Will grow and shrink as needed taking initial size into account -->
</div>
<div class="flex-auto ...">
<!-- Will grow and shrink as needed taking initial size into account -->
</div>
</div>
<div class="flex ...">
<div class="flex-1 ...">
<!-- Will grow and shrink as needed -->
</div>
<div class="flex-none ...">
<!-- Will not grow or shrink -->
</div>
<div class="flex-1 ...">
<!-- Will grow and shrink as needed -->
</div>
</div>
To control how a flex item both grows and shrinks at a specific breakpoint, add a {screen}:
prefix to any existing utility class. For example, use md:flex-1
to apply the flex-1
utility at only medium screen sizes and above.
<div class="flex ...">
<!-- ... -->
<div class="flex-none md:flex-1 ...">
Responsive flex item
</div>
<!-- ... -->
</div>
For more information about Tailwind's responsive design features, check out the Responsive Design documentation.
By default, Tailwind provides four flex
utilities. You change, add, or remove these by editing the theme.flex
section of your Tailwind config.
// tailwind.config.js
module.exports = {
theme: {
flex: {
'1': '1 1 0%',
auto: '1 1 auto',
- initial: '0 1 auto',
+ inherit: 'inherit',
none: 'none',
+ '2': '2 2 0%',
}
}
}
By default, only responsive variants are generated for flex utilities.
You can control which variants are generated for the flex utilities by modifying the flex
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: {
// ...
+ flex: ['hover', 'focus'],
}
}
}
If you don't plan to use the flex utilities in your project, you can disable them entirely by setting the flex
property to false
in the corePlugins
section of your config file:
// tailwind.config.js
module.exports = {
corePlugins: {
// ...
+ flex: false,
}
}