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; / 4px /
basis-2flex-basis: 0.5rem; / 8px /
basis-3flex-basis: 0.75rem; / 12px /
basis-4flex-basis: 1rem; / 16px /
basis-5flex-basis: 1.25rem; / 20px /
basis-6flex-basis: 1.5rem; / 24px /
basis-7flex-basis: 1.75rem; / 28px /
basis-8flex-basis: 2rem; / 32px /
basis-9flex-basis: 2.25rem; / 36px /
basis-10flex-basis: 2.5rem; / 40px /
basis-11flex-basis: 2.75rem; / 44px /
basis-12flex-basis: 3rem; / 48px /
basis-14flex-basis: 3.5rem; / 56px /
basis-16flex-basis: 4rem; / 64px /
basis-20flex-basis: 5rem; / 80px /
basis-24flex-basis: 6rem; / 96px /
basis-28flex-basis: 7rem; / 112px /
basis-32flex-basis: 8rem; / 128px /
basis-36flex-basis: 9rem; / 144px /
basis-40flex-basis: 10rem; / 160px /
basis-44flex-basis: 11rem; / 176px /
basis-48flex-basis: 12rem; / 192px /
basis-52flex-basis: 13rem; / 208px /
basis-56flex-basis: 14rem; / 224px /
basis-60flex-basis: 15rem; / 240px /
basis-64flex-basis: 16rem; / 256px /
basis-72flex-basis: 18rem; / 288px /
basis-80flex-basis: 20rem; / 320px /
basis-96flex-basis: 24rem; / 384px /
basis-autoflex-basis: auto;
basis-pxflex-basis: 1px;
basis-0.5flex-basis: 0.125rem; / 2px /
basis-1.5flex-basis: 0.375rem; / 6px /
basis-2.5flex-basis: 0.625rem; / 10px /
basis-3.5flex-basis: 0.875rem; / 14px /
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 = {
  2. theme: {
  3. extend: {
  4. spacing: {
  5. '112': '28rem',
  6. '128': '32rem',
  7. }
  8. }
  9. }
  10. }

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 = {
  2. theme: {
  3. extend: {
  4. flexBasis: {
  5. '1/7': '14.2857143%',
  6. '2/7': '28.5714286%',
  7. '3/7': '42.8571429%',
  8. '4/7': '57.1428571%',
  9. '5/7': '71.4285714%',
  10. '6/7': '85.7142857%',
  11. }
  12. }
  13. }
  14. }

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="basis-[14.2857143%]">
  2. <!-- ... -->
  3. </div>

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