Flexbox & Grid

Flex Basis

Utilities for controlling the initial size of flex items.

Quick reference

Class
Properties
basis-0flex-basis: 0px;
basis-1flex-basis: 0.25rem;
basis-2flex-basis: 0.5rem;
basis-3flex-basis: 0.75rem;
basis-4flex-basis: 1rem;
basis-5flex-basis: 1.25rem;
basis-6flex-basis: 1.5rem;
basis-7flex-basis: 1.75rem;
basis-8flex-basis: 2rem;
basis-9flex-basis: 2.25rem;
basis-10flex-basis: 2.5rem;
basis-11flex-basis: 2.75rem;
basis-12flex-basis: 3rem;
basis-14flex-basis: 3.5rem;
basis-16flex-basis: 4rem;
basis-20flex-basis: 5rem;
basis-24flex-basis: 6rem;
basis-28flex-basis: 7rem;
basis-32flex-basis: 8rem;
basis-36flex-basis: 9rem;
basis-40flex-basis: 10rem;
basis-44flex-basis: 11rem;
basis-48flex-basis: 12rem;
basis-52flex-basis: 13rem;
basis-56flex-basis: 14rem;
basis-60flex-basis: 15rem;
basis-64flex-basis: 16rem;
basis-72flex-basis: 18rem;
basis-80flex-basis: 20rem;
basis-96flex-basis: 24rem;
basis-autoflex-basis: auto;
basis-pxflex-basis: 1px;
basis-0.5flex-basis: 0.125rem;
basis-1.5flex-basis: 0.375rem;
basis-2.5flex-basis: 0.625rem;
basis-3.5flex-basis: 0.875rem;
basis-1/2flex-basis: 50%;
basis-1/3flex-basis: 33.333333%;
basis-2/3flex-basis: 66.666667%;
basis-1/4flex-basis: 25%;
basis-2/4flex-basis: 50%;
basis-3/4flex-basis: 75%;
basis-1/5flex-basis: 20%;
basis-2/5flex-basis: 40%;
basis-3/5flex-basis: 60%;
basis-4/5flex-basis: 80%;
basis-1/6flex-basis: 16.666667%;
basis-2/6flex-basis: 33.333333%;
basis-3/6flex-basis: 50%;
basis-4/6flex-basis: 66.666667%;
basis-5/6flex-basis: 83.333333%;
basis-1/12flex-basis: 8.333333%;
basis-2/12flex-basis: 16.666667%;
basis-3/12flex-basis: 25%;
basis-4/12flex-basis: 33.333333%;
basis-5/12flex-basis: 41.666667%;
basis-6/12flex-basis: 50%;
basis-7/12flex-basis: 58.333333%;
basis-8/12flex-basis: 66.666667%;
basis-9/12flex-basis: 75%;
basis-10/12flex-basis: 83.333333%;
basis-11/12flex-basis: 91.666667%;
basis-fullflex-basis: 100%;

Show all classes

Basic usage

Setting the flex basis

Use the basis-{size} utilities to set the initial size of flex items.

Flex Basis - 图1

  1. <div class="flex flex-row">
  2. <div class="basis-1/4">01</div>
  3. <div class="basis-1/4">02</div>
  4. <div class="basis-1/2">03</div>
  5. </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.

  1. <div class="basis-1/3 hover:basis-1/2">
  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:basis-1/3 to apply the basis-1/3 utility at only medium screen sizes and above.

  1. <div class="flex flex-row">
  2. <div class="basis-1/4 md:basis-1/3">01</div>
  3. <div class="basis-1/4 md:basis-1/3">02</div>
  4. <div class="basis-1/2 md:basis-1/3">03</div>
  5. </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.

tailwind.config.js

  1. 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.

tailwind.config.js

  1. 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.

  1. <div class="flex-basis-[14.2857143%]">
  2. <!-- ... -->
  3. </div>

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