flex
Widely availableSince 201597% of users
Sets how much a flex item grows, how much it shrinks and the size it starts from, all in one line. flex: 1 makes items split the free space evenly.
What's modern
From web-features, MDN's browser data and our snippets, checked dailyClassic, with newer partsIt has worked everywhere since September 2015, and it keeps getting newer values.
Newer parts of flex
fit-contentBaseline Sept 2022, Widely Mar 2025max-contentBaseline Sept 2022, Widely Mar 2025min-contentBaseline Sept 2022, Widely Mar 2025contentBaseline Sept 2021, Widely Mar 2024
See how modern your own CSS is.Check your CSS →
Quick facts
- Initial value
0 1 auto- Inherited
- No
- Applies to
- flex items and in-flow pseudo-elements
- Animation type
- byComputedValueType
Quick example
.layout {
display: flex;
}
.sidebar {
flex: 0 0 15rem;
}
.main {
flex: 1;
}Values
noneauto<'flex-grow'><'flex-shrink'><'flex-basis'>Examples
Equal columns
.row {
display: flex;
}
.row > * {
flex: 1;
}flex: 1 sets flex-grow to 1, flex-shrink to 1 and flex-basis to 0. Every child starts from zero and gets an equal share of the row.
Fixed sidebar, flexible content
.sidebar {
flex: none;
width: 16rem;
}
.content {
flex: auto;
}flex: none (0 0 auto) keeps the sidebar at its width. flex: auto (1 1 auto) lets the content area grow and shrink from its own size.
Cards that wrap
.cards {
display: flex;
flex-wrap: wrap;
gap: 1rem;
}
.card {
flex: 1 1 15rem;
}Each card starts at 15rem and grows to fill its row. When a row runs out of room, the next card wraps to a new line.
Common pitfalls
- flex: 1 is not the same as flex-grow: 1flex: 1 also sets flex-basis to 0. flex-grow: 1 on its own leaves flex-basis at auto, so items start from their content size and can end up with different widths.
- Items won't shrink below their contentA flex item's minimum size defaults to the size of its content, so a long word or a wide table can stop it from shrinking. Set min-width: 0, or overflow: hidden or auto, to let it get smaller.
- It only works on flex itemsflex has no effect unless the parent is a flex container, set with display: flex or display: inline-flex.
flex browser support
BaselineWidely availableThis feature is well established and works across many devices and browser versions. It has been available across browsers since 2015.Safe to use without fallbacks.
Usage97%of people can use this3% use a browser without it.
Browsers
29+
22+
9+
12+Mobile
29+Android
22+Android
9+iOS