flex-basis
Sets a flex item’s starting size on the main axis, before it grows or shrinks.
- Initial value
auto- Inherited
- No
- Animatable
- yes, as a length or percentage
- Applies to
- flex items
- JavaScript
element.style.flexBasis = "200px"
Example
#.columns {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
.columns > * {
flex: 1 1 180px;
}<div class="columns stage">
<div class="box">Module 1</div><div class="box">Module 2</div><div class="box">Module 3</div>
</div>Definition and usage
#The flex-basis property defines the starting point for an item’s size on the main axis. Every item first gets its base size, and only afterward is any free or missing space distributed according to flex-grow and flex-shrink.
With auto, an item looks at its width (or height in a column), and if that isn’t set, at the size of its content. The value 0 means starting from zero, so with an equal flex-grow the items end up exactly the same size.
In a container with flex-direction: column, flex-basis applies to the height, not the width.
Syntax
#flex-basis: auto | content | <length> | <percentage>;Values
#- The starting point is the content, so items end up with different widths.
- All items start from zero, so with an equal grow value they’re equally wide.
<length>
Every item starts at 100px and shares the rest of the space.<percentage>
The base size is half the container, so the items have to shrink.
Values in practice
#auto
.demo .box { flex-basis: auto; }0
.demo .box { flex-basis: 0; }100px
.demo .box { flex-basis: 100px; }50%
.demo .box { flex-basis: 50%; }Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#flex: 1 1 200pxis a simple way to get columns that wrap once things get too narrow.- When you set both
widthandflex-basis,flex-basistakes priority (except for the valueauto).
Related entries
#Spotted a mistake or missing an example? Write to us.