CSS flex-basis Property

Beginner
6 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The flex-basis property sets the initial main size of a flex item — before flex-grow and flex-shrink share free or overflow space.

In a row flex container it is the starting width. In a column container it is the starting height. The initial value is auto. It applies only to flex items and is not inherited.

Baseline · Widely available.

Not deprecated and not experimental. Available across browsers since about September 2015.

Shorthand tip.

For everyday layouts, prefer the flex shorthand (flex: 1, flex: auto). It sets grow, shrink, and basis together. Use flex-basis alone when you only need to change the starting size.

CSS Syntax

syntax.css
flex-basis: <length> | <percentage> | auto | content | initial | inherit;

You can also use intrinsic keywords such as min-content, max-content, and fit-content.

Property Values

ValueDescriptionTry it
autoDefault. Uses width/height, or content size when those are autoTry it
<length>Fixed start size, such as 120px or 10emTry it
<percentage>Percent of the flex container’s main size, such as 40%Try it
0Start from zero main size (common with flex-grow: 1 for equal columns)Try it
contentSize based on the item’s contentTry it
initialSets this property to its default value, autoTry it
inheritInherits this property from the parent elementTry it

How to Use flex-basis

Put items in a flex container, then set each item’s starting main size.

  1. On the parent, set display: flex (and flex-direction if needed).
  2. On a flex item, set flex-basis to a length, percent, auto, or 0.
  3. Add flex-grow / flex-shrink if the item should fill or compress after that start size.
  4. Or use flex: 1 / flex: auto when you want the common grow + shrink + basis combo.
GoalTypical setting
Start from content / widthflex-basis: auto (default)
Fixed starting widthflex-basis: 120px
Share of the containerflex-basis: 40%
Equal columnsflex-basis: 0 with flex-grow: 1

Live Preview

Three items can grow and shrink. Change flex-basis on the first (blue) item only.

All items use flex-grow: 1 and flex-shrink: 1. Basis is the starting size before that sharing.

Flex row
One
Two
Three

flex-basis: auto

CSS Examples

Each snippet shows only the flex container and the flex-basis you are studying. Use Try It Yourself for a live editor.

Example 1 — Fixed Length

Give the first item a pixel starting size. Other items still share the rest.

CSS
<style>
  section {
    display: flex;
  }

  div {
    flex-grow: 1;
    flex-shrink: 1;
    flex-basis: auto;
  }

  .first {
    flex-basis: 120px;
  }
</style>

<section>
  <div class="first">120px</div>
  <div>Two</div>
  <div>Three</div>
</section>
Try It Yourself

How It Works

  1. Make a flex row. display: flex turns the children into flex items.
  2. Set a start size. flex-basis: 120px gives the first item a 120px main-size start.
  3. Allow sharing. flex-grow / flex-shrink still adjust sizes after that start.
  4. Compare siblings. Items Two and Three keep auto and share leftover space.

Example 2 — Percentage of the Container

Use a percent so the start size scales with the flex container.

CSS
<style>
  section {
    display: flex;
  }

  div {
    flex-grow: 1;
    flex-shrink: 1;
    flex-basis: auto;
  }

  .first {
    flex-basis: 40%;
  }
</style>

<section>
  <div class="first">40%</div>
  <div>Two</div>
  <div>Three</div>
</section>
Try It Yourself

How It Works

  1. Resolve against the container. 40% means 40% of the flex container’s main size.
  2. Then grow or shrink. Free space is still shared because grow and shrink are on.
  3. Need a definite container size. If the container’s main size is indefinite, percent basis may fall back toward content sizing.
  4. Resize the window. The first item’s start target scales with the row width.

Example 3 — Equal Columns with 0

Start every item at zero, then grow equally so content width does not win.

CSS
<style>
  section {
    display: flex;
  }

  div {
    flex-grow: 1;
    flex-shrink: 1;
    flex-basis: 0;
  }
</style>

<section>
  <div>Short</div>
  <div>A bit longer text</div>
  <div>OK</div>
</section>
Try It Yourself

How It Works

  1. Start from zero. flex-basis: 0 ignores content width as the starting size.
  2. Grow the same amount. Each item has flex-grow: 1, so free space is split evenly.
  3. Result. The three columns end up the same width even with different text lengths.
  4. Same idea as flex: 1. The shorthand usually expands to grow 1, shrink 1, basis 0% (or similar).

Edge Cases & Pitfalls

If sizes look wrong, check whether basis, width, or grow/shrink is winning.

flex item

Only works on flex items

The parent needs display: flex or inline-flex. On a normal block, flex-basis has no effect.

width

Non-auto basis beats width

In a row container, a length or percent flex-basis overrides width for the main size. With auto, width is used.

0 vs 0%

0 and 0% are not always identical

A length 0 is absolute. A percent needs a definite container main size; otherwise it can resolve like content sizing (especially in column layouts).

min-size

Content can still block shrinking

Even with a small basis, the automatic minimum size can keep an item from shrinking below its content. Use min-width: 0 when overflow is expected.

shorthand

Setting flex resets basis

A later flex shorthand overwrites grow, shrink, and basis together. Put longhand flex-basis after the shorthand if you need both.

Browser Support

flex-basis is a browser CSS property for flex items. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

flex-basis

Supported in all modern browsers since about September 2015. Part of the CSS Flexible Box Layout module.

98% Flex support
Google Chrome 29+
Full support
Mozilla Firefox 22+
Full support
Apple Safari 9+
Full support
Microsoft Edge 12+
Full support
Opera 17+
Full support
Samsung Internet 2+
Full support
Internet Explorer 11
Partial support
flex-basis Widely supported

Bottom line: Safe for production flex layouts. Prefer the flex shorthand for common patterns. It is not a runtime API.

Key Takeaways

  • Role: set the initial main size of a flex item before grow and shrink.
  • Default: auto — follow width/height or content.
  • Equal columns: flex-basis: 0 with matching flex-grow values.
  • Everyday tip: prefer flex: 1 / flex: auto unless you need basis alone.

One line: flex-basis is the starting main size — then grow and shrink finish the layout.

Frequently Asked Questions

It sets the initial main size of a flex item before flex-grow and flex-shrink share free or overflow space. In a row container that is the starting width; in a column container it is the starting height.
The initial value is auto. The browser uses the item's width or height when set, or sizes from content when those are also auto.
On a flex item, a non-auto flex-basis sets the main-size start and wins over width in a row flex container. When flex-basis is auto, width (or height in a column) is used instead.
The item starts from zero main size before growing. With flex-grow: 1 on siblings, this is a common way to make equal-width columns that ignore content width.
MDN recommends the flex shorthand (for example flex: 1 or flex: auto) for everyday layouts, because it sets grow, shrink, and basis together. Use flex-basis alone when you only need to change the starting size.
It is Baseline and widely available in modern browsers since about 2015. It is a browser CSS property for flex items, not a Node.js feature.

Next: flex-direction

Learn how to switch the main axis between row and column.

flex-direction tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful