Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Flexbox

The flex-basis property

Reference for the CSS flex-basis property: how it sets a flex item's starting main size, how it differs from width, and what auto, content and 0 mean.

The flex-basis property sets the starting size of a flex item along the main axis, before the container hands out extra space (flex-grow) or takes space back (flex-shrink). In a row container it works like width; in a column container it works like height.

Most of the time you set it through the flex shorthand, but the longhand is handy when you want to change just the basis.

CSS
.card { flex-basis: 240px; }
.grow { flex-basis: 0; }   /* start from nothing, then grow */

Try it

flex-basis with growing
flex-basis beats width

Syntax

CSS
flex-basis: auto | content | <'width'>;

flex-basis: auto;
flex-basis: 12rem;
flex-basis: 30%;
flex-basis: content;
  • Initial value: auto
  • Applies to: flex items
  • Inherited: no
  • Percentages: relative to the flex container's inner main size
  • Animatable: yes, as a length or percentage
  • Computed value: as specified, with lengths made absolute

Values

Value Description
auto Use the item's width (or height in a column container). If that is also auto, use the content size.
content Size from the content, ignoring width and height.
<length> A fixed starting size such as 200px or 12rem.
<percentage> A share of the container's main size. If the container's size depends on its content, it behaves like content.
sizing keywords min-content, max-content and fit-content are accepted, as for width. Support for keywords other than auto, content and lengths has varied, so check your target browsers.

Usage notes

  • A basis of 0 changes the maths. With flex: 1 1 0 (or just flex: 1) the whole container width is free space, so growing items get proportional widths regardless of content. With auto, content widths are taken first and only the leftover is shared.
  • It wins over width. When the basis is not auto, it replaces width as the item's starting main size. min-width and max-width still clamp the final result.
  • It is not a guarantee. An item with flex-basis: 200px can still become narrower (shrink) or wider (grow). Use flex: none or flex: 0 0 200px when it must stay put.
  • Gaps are not included. gap is subtracted from the free space before items grow, so percentages that add up to 100% plus a gap will overflow and shrink.
  • Box sizing counts. With box-sizing: border-box, the basis includes padding and border.
  • Columns. Inside flex-direction: column, the basis controls height. If the container has no fixed height, there is little free space to share.

Browser support

Supported in every browser. The content keyword is also supported in current browsers.