CSS flex-basis Property

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 4 Examples
Flexbox

What You’ll Learn

The flex-basis property sets the starting size of a flex item along the main axis before grow and shrink adjust the final layout. It is a key piece of the Flexbox sizing puzzle.

01

Initial size

Before grow/shrink.

02

Syntax

px, %, auto.

03

Default auto

Content-based size.

04

Flex items

Child elements only.

05

vs width

Main axis priority.

06

flex shorthand

Third value in flex.

Introduction

The flex-basis property in CSS is used in the context of Flexbox layouts. It defines the initial main size of a flex item before any space distribution happens.

This property helps in determining the starting size of an item within a flex container, which can be different from the final size after the flexbox algorithm has been applied.

Definition and Usage

Apply flex-basis on direct children of a flex container. Use pixel values for fixed starting widths, percentages for proportional columns, and auto when you want content to determine the starting size. Pair it with flex-grow and flex-shrink (or the flex shorthand) for full control.

💡
Beginner Tip

flex: 1 sets flex-basis: 0% internally. That is why equal columns ignore their content width and share space evenly.

📝 Syntax

The syntax for the flex-basis property is simple and can be specified in various units such as pixels, percentages, or the keyword auto.

syntax.css
element {
  flex-basis: value;
}

Here, value can be a length value (e.g., px, em, rem), a percentage, or the keyword auto.

Basic Example

flex-basis-200px.css
.sidebar {
  flex-basis: 200px;
}
flex-basis: auto; flex-basis: 200px; flex-basis: 30%; flex-basis: 0;

Default Value

The default value of the flex-basis property is auto, which means the size of the flex item is based on its content.

Syntax Rules

  • Only applies to flex items inside a flex container.
  • In a row flex container, flex-basis sets the initial width; in a column container, it sets the initial height.
  • When set, flex-basis overrides width (row) or height (column) as the starting main size.
  • Final size may change after flex-grow and flex-shrink run.
  • The property is not inherited.

⚡ Quick Reference

QuestionAnswer
Initial valueauto
Applies toFlex items
InheritedNo
AnimatableYes (length and percentage values)
Part of shorthandThird value in flex: grow shrink basis

💎 Property Values

ValueDescription
lengthSpecifies a fixed size for the flex item (e.g., 100px, 2em).
percentageSpecifies a size relative to the flex container’s main size (e.g., 50%).
autoThe browser calculates the size based on the item’s content.
contentSize based on the content (limited browser support).

flex-basis vs width

PropertyWhen to useNotes
flex-basisFlex item main-axis starting sizeRespected by the flex layout algorithm first
widthGeneral element widthUsed as fallback when flex-basis is auto
flex: 0 0 200pxFixed 200px item that won’t grow or shrinkShorthand combining grow, shrink, and basis

👀 Live Preview

Three flex items with flex-basis: 120px, 30%, and auto:

120px
30%
Auto

Examples Gallery

In this example, we’ll set the flex-basis of flex items to different values to see how it affects their initial size — plus a sidebar, percentage columns, and equal columns with flex-basis: 0.

📏 Basic flex-basis Values

Start with the reference example — pixel, percentage, and auto basis on three items.

Example 1 — Pixel, Percentage, and Auto

Set different starting sizes to see how flex-basis controls the initial layout before grow and shrink apply.

flex-basis-mixed.html
<style>
  .container {
    display: flex;
    border: 1px solid #000;
    padding: 10px;
  }
  .item1 { flex-basis: 200px; }
  .item2 { flex-basis: 30%; }
  .item3 { flex-basis: auto; }
</style>

<div class="container">
  <div class="item item1">200px</div>
  <div class="item item2">30%</div>
  <div class="item item3">Auto</div>
</div>
Try It Yourself

How It Works

Item 1 starts at 200px, item 2 at 30% of the container width, and item 3 sizes itself from its content because basis is auto.

Example 2 — Fixed Sidebar Basis

Lock a sidebar to 250px starting width with flex-basis: 250px and flex-shrink: 0.

flex-basis-sidebar.css
.sidebar {
  flex-basis: 250px;
  flex-shrink: 0;
}
Try It Yourself

How It Works

flex-shrink: 0 prevents the sidebar from getting narrower than its basis when space is tight.

🗃 Layout Patterns

Use percentage basis for proportional columns and zero basis for equal flexible tracks.

Example 3 — Percentage-Based Columns

Split a row into 25% and 75% starting widths using percentage flex-basis values.

flex-basis-percent.css
.col-small { flex-basis: 25%; }
.col-large { flex-basis: 75%; }
Try It Yourself

How It Works

Percentages are relative to the flex container’s inner main size, making proportional layouts easy to express.

Example 4 — Equal Columns with flex-basis: 0

Combine flex-basis: 0 with flex-grow: 1 so columns share space equally regardless of content width.

flex-basis-zero.css
.column {
  flex-grow: 1;
  flex-basis: 0;
}

This is equivalent to flex: 1.

Try It Yourself

How It Works

Starting from zero basis, all grow values share leftover space equally, so short and long labels get the same column width.

♿ Accessibility

  • Avoid squeezing content too small — very small flex-basis values can make text unreadable on narrow screens.
  • Test with zoom and large text — fixed pixel basis may not leave enough room for enlarged content.
  • Use wrapping when needed — combine with flex-wrap: wrap on the container for mobile layouts.
  • Keep logical source order — flex-basis changes size, not reading order.
  • Do not hide content by setting basis to 0 without overflow handling — ensure content remains accessible.

🧠 How flex-basis Works

1

Flex container lays out items

Each flex item receives a starting main size from flex-basis (or content when auto).

Initial size
2

Free space is calculated

The browser compares the sum of basis sizes to the container’s available main size.

Calculation
3

Grow or shrink adjusts final size

flex-grow expands items into extra space; flex-shrink reduces overflow.

Distribution
=

Predictable flex sizing

You control where each item starts before Flexbox fine-tunes the result.

🖥 Browser Compatibility

The flex-basis property is well-supported in modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. It is safe to use in most web projects, but as always, testing across different browsers is recommended to ensure compatibility.

Baseline · Universal support

flex-basis everywhere

The flex-basis property is part of standard Flexbox and works in all modern browsers.

99% Universal support
Google Chrome 29+ · Desktop & Mobile
Full support
Mozilla Firefox 28+ · Desktop & Mobile
Full support
Apple Safari 9+ · macOS & iOS
Full support
Microsoft Edge 12+ · All versions
Full support
Opera 17+ · Modern versions
Full support
flex-basis property 99% supported

Bottom line: flex-basis is safe for all modern Flexbox layouts. The content keyword has limited support — prefer auto or length values.

🎉 Conclusion

The flex-basis property is a crucial part of creating flexible and responsive layouts using CSS Flexbox. By defining the initial main size of a flex item, you can control how your flex items are displayed before any additional space is distributed.

This property, along with others in the Flexbox module, provides powerful tools for building modern web layouts that adapt to different screen sizes and content requirements.

💡 Best Practices

✅ Do

  • Use flex-basis for the starting main-axis size of flex items
  • Combine with flex-shrink: 0 for fixed-width sidebars
  • Use percentages for proportional column layouts
  • Use flex-basis: 0 with flex-grow: 1 for equal columns
  • Prefer the flex shorthand when setting all three values together

❌ Don’t

  • Apply flex-basis without a flex container parent
  • Assume basis is the final size — grow and shrink may change it
  • Rely on the content keyword in production yet
  • Set tiny basis values that truncate readable text
  • Confuse flex-basis with min-width or max-width constraints

Key Takeaways

Knowledge Unlocked

Five things to remember about flex-basis

Use these points when sizing flex items.

5
Core concepts
02

auto

Default value.

Default
📐 03

px & %

Fixed or relative.

Values
🛠 04

flex shorthand

Third component.

Related
📈 05

basis: 0

Equal columns.

Pattern

❓ Frequently Asked Questions

The flex-basis property sets the initial main size of a flex item before flex-grow and flex-shrink distribute extra or overflow space. It is the starting width in a row flex container, or starting height in a column flex container.
The initial value is auto, which means the browser calculates the size based on the item's content and width or height properties.
On a flex item, flex-basis sets the starting size along the main axis and takes priority over width in a row flex container. width still affects the element when flex-basis is auto.
flex-basis: 0 (or 0%) makes the item start from zero main size before growing. Combined with flex-grow, this is how flex: 1 creates equal columns that ignore content width.
Yes. flex-basis: 30% sets the initial size to 30% of the flex container's main size. The final size may still change if flex-grow or flex-shrink apply.

Practice in the Live Editor

Open the HTML editor, set flex-basis: 200px, 30%, and auto on flex items, and compare the results.

HTML Editor →

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.

5 people found this page helpful