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.
Fundamentals
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.
Foundation
📝 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.
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.
Cheat Sheet
⚡ Quick Reference
Question
Answer
Initial value
auto
Applies to
Flex items
Inherited
No
Animatable
Yes (length and percentage values)
Part of shorthand
Third value in flex: grow shrink basis
Reference
💎 Property Values
Value
Description
length
Specifies a fixed size for the flex item (e.g., 100px, 2em).
percentage
Specifies a size relative to the flex container’s main size (e.g., 50%).
auto
The browser calculates the size based on the item’s content.
content
Size based on the content (limited browser support).
Context
flex-basis vs width
Property
When to use
Notes
flex-basis
Flex item main-axis starting size
Respected by the flex layout algorithm first
width
General element width
Used as fallback when flex-basis is auto
flex: 0 0 200px
Fixed 200px item that won’t grow or shrink
Shorthand combining grow, shrink, and basis
Preview
👀 Live Preview
Three flex items with flex-basis: 120px, 30%, and auto:
120px
30%
Auto
Hands-On
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.
Starting from zero basis, all grow values share leftover space equally, so short and long labels get the same column width.
A11y
♿ 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.
Compatibility
🖥 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 Chrome29+ · Desktop & Mobile
Full support
Mozilla Firefox28+ · Desktop & Mobile
Full support
Apple Safari9+ · macOS & iOS
Full support
Microsoft Edge12+ · All versions
Full support
Opera17+ · Modern versions
Full support
flex-basis property99% supported
Bottom line:flex-basis is safe for all modern Flexbox layouts. The content keyword has limited support — prefer auto or length values.
Wrap Up
🎉 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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about flex-basis
Use these points when sizing flex items.
5
Core concepts
📏01
Initial size
Before grow/shrink.
Purpose
⚙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.