Basic usage
Setting the flex basis
Use the basis-{size}
utilities to set the initial size of flex items.
<div class="flex flex-row">
<div class="basis-1/4">01</div>
<div class="basis-1/4">02</div>
<div class="basis-1/2">03</div>
</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:basis-1/2
to only apply the basis-1/2
utility on hover.
<div class="basis-1/3 hover:basis-1/2">
<!-- ... -->
</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:basis-1/3
to apply the basis-1/3
utility at only medium screen sizes and above.
<div class="flex flex-row">
<div class="basis-1/4 md:basis-1/3">01</div>
<div class="basis-1/4 md:basis-1/3">02</div>
<div class="basis-1/2 md:basis-1/3">03</div>
</div>
To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.
Using custom values
Customizing your theme
The default flex basis scale is a combination of the default spacing scale as well as a set of percentage based values.
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: { '112': '28rem', '128': '32rem', } } }}
Alternatively, you can customize just the flex basis scale by editing theme.flexBasis
or theme.extend.flexBasis
in your tailwind.config.js
file.
module.exports = { theme: { extend: { flexBasis: { '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.
Arbitrary values
If you need to use a one-off flex-basis
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="basis-[14.2857143%]">
<!-- ... -->
</div>
Learn more about arbitrary value support in the arbitrary values documentation.