Flex Sizing: flex-basis, flex-grow, flex-shrink and the flex Shorthand
How flexbox sizes items: the flex-basis starting size, how flex-grow shares free space and flex-shrink removes overflow weighted by size, the automatic minimum size and min-width: 0, the flex shorthand keywords, and unequal flex: 1.
kvi5hnuCode Sprout team member10 min readOn this page
Flexbox's main job is deciding how big each item is along the main axis. Every item starts at a base size, then the browser compares the total with the container: if there's room left over, items with flex-grow share it; if they overflow, items with flex-shrink give some up. Three properties control this, usually set together with the flex shorthand.
flex-basis: the starting size
flex-basis is the item's size along the main axis before growing or shrinking: its width in a row, its height in a column.
| Value | Starting size |
|---|---|
auto (initial) | the item's width (or height in a column); if that's auto too, the size of its content |
a length or percentage, such as 200px, 30% | exactly that, ignoring width |
content | the content's size, even if width is set |
0 | nothing: all the item's size then comes from growing |
flex-basis beats width: tested in Chrome, an item with flex-basis: 200px; width: 50px is 200px wide. min-width and max-width still apply on top. Percentages are relative to the container's main size, and box-sizing decides whether the basis includes padding and borders, just like width.
flex-grow: sharing free space
When the items' base sizes add up to less than the container, the remaining free space is shared out in proportion to flex-grow. The initial value, 0, means the item doesn't grow.

Tested in Chrome: three items with flex-basis: 100px in a 600px container, with flex-grow 1, 2 and 0. The 300px of free space is split into 3 units of 100px; the first item gets one unit and the second gets two. The results are 200px, 300px and 100px. The grow factor shares the free space, not the total width: an item with flex-grow: 2 isn't twice as wide as one with flex-grow: 1, unless both start at 0.
If an item hits its max-width, it stops there, and its share goes to the other items: in a 600px container, three flex: 1 items, one of them with max-width: 100px, end up 100px, 250px and 250px.
flex-shrink: removing overflow
When the base sizes add up to more than the container, and the container doesn't wrap, the items shrink. The initial value of flex-shrink is 1, so by default every item shrinks.
Shrinking is weighted by size: each item gives up an amount proportional to flex-shrink × flex-basis, so a large item loses more than a small one with the same factor. Tested in Chrome:
- Two 400px items in a 600px container overflow by 200px. With
flex-shrink1 and 3, the weights are 400 and 1200, so they lose 50px and 150px, ending at 350px and 250px. - Items of 300px and 500px with the default
flex-shrink: 1lose 75px and 125px, ending at 225px and 375px: the same proportion of their size.
flex-shrink: 0 stops an item shrinking. Use it on icons, avatars and buttons that must keep their size:
.avatar { flex-shrink: 0; inline-size: 2.5rem; }
The minimum size, and min-width: 0
Items don't shrink below their automatic minimum size. A flex item's min-width (or min-height in a column) defaults to auto, which for a flex item means about its min-content size: the width of its longest word, its widest image or its unbreakable content, or its width if that's set and smaller. Scroll containers are the exception: an item with overflow: hidden, auto or scroll has no automatic minimum. overflow: clip doesn't count, because it doesn't make a scroll container.
That's behind two common surprises:
- A long URL, a
<pre>block or a wide table inside a flex item pushes the item, and the whole layout, wider than the container. - Items with
flex: 1aren't equal. Tested in Chrome: threeflex: 1items in 600px, the first containing an unbroken word 202.6px wide, are 202.6px, 198.7px and 198.7px: the first can't go below its content's width, and the other two share what's left.

In the middle row the sidebar is the one that gives way, shrinking to its own minimum, while the address can't.
The fix is to allow the item to shrink below its content, and let the content wrap or scroll:
.main { flex: 1; min-width: 0; } /* now it can shrink */
.main a { overflow-wrap: anywhere; } /* long URLs break */
.main pre { overflow-x: auto; } /* code scrolls inside */
Making the item a scroll container also removes the automatic minimum: overflow: hidden clips the content, auto makes the item scroll. overflow: clip doesn't, as tested in Chrome. In a column, the same problem shows up as an item that won't shrink in height, and min-height: 0 is the fix. It's needed most when the scrolling element is nested inside a flex item that doesn't scroll itself (article 65).
The flex shorthand
flex sets flex-grow, flex-shrink and flex-basis together. It's recommended over the separate properties, because its keywords set sensible combinations, and a missing basis becomes 0, not auto:
| Shorthand | Equals | Meaning |
|---|---|---|
flex: initial | 0 1 auto | the default: sized by width or content, shrinks but doesn't grow |
flex: auto | 1 1 auto | sized by content, then shares free space and shrinks |
flex: none | 0 0 auto | fixed at its width or content size; doesn't grow or shrink |
flex: 1 | 1 1 0% | starts from 0, so all the space is shared: equal widths, within minimum sizes |
flex: 2 | 2 1 0% | twice the share of a flex: 1 sibling |
flex: 0 | 0 1 0% | starts from 0 and doesn't grow: shrinks to its minimum content size |
flex: 1 1 15rem | starts at 15rem, then grows and shrinks | |
flex: 15rem | 1 1 15rem | a single length sets the basis, with grow and shrink 1 |
The computed values were checked in Chrome. The difference between flex: auto and flex: 1 is the basis:
- With
flex: auto, items start at their content orwidth, and only the leftover space is shared, so bigger items stay bigger. Tested in Chrome: items of 300px and 100px withflex: autoin 600px become 400px and 200px. - With
flex: 1, items start at 0, so all the space is shared equally, as long as no item hits its minimum size.

Compare the second and third rows: the same three texts, and only the basis differs, auto or 0%.
One more subtlety: with flex: 1, only the content box starts at 0, and padding and borders are added on top. Tested in Chrome: two flex: 1 items in 600px, with 150px and 50px of inline padding on each side, are 400px and 200px wide. For truly equal columns whatever their padding, grid's 1fr columns (article 67) are simpler.
body { font: 0.8rem system-ui, sans-serif; margin: 1rem; }
.controls { margin-bottom: 0.75rem; }
.row {
display: flex; gap: 0.3rem;
inline-size: var(--w, 16rem);
padding: 0.3rem; margin-bottom: 0.6rem;
border: 2px dashed #8a3b12; border-radius: 8px;
}
.row > div { padding: 0.4rem; border-radius: 6px; background: #f4efe6; border: 1px solid #8a3b12; }
.row .a { flex: 1; }
.row .b { flex: 2; background: #dff0e5; border-color: #2f7d4f; }
.row .c { flex: none; inline-size: 6rem; background: #fde2e1; border-color: #b3261e; }
.row.auto .a, .row.auto .b { flex: auto; }
.row.url .link { flex: 1; }
.row.url .c { inline-size: 3.5rem; }
.row.url .fix { min-width: 0; overflow-wrap: anywhere; }
.note { color: #555; margin: 0; }
Narrow the container. In the first row, C stays 6rem because of flex: none, and A and B share the rest 1 : 2, until, below about 14rem, they reach their minimum content size, stop sharing and the row overflows. In the second, the item with more text is wider because flex: auto starts from the content. In the last two, the first link refuses to get narrower than its URL and pushes the button out of the box, while the second wraps.
Flex sizing in columns
In flex-direction: column, the same rules apply to height. They only matter when the container has a definite height: otherwise the column is just as tall as its content and there's no free space to share. A full-height layout with a scrolling middle:
.app { display: flex; flex-direction: column; block-size: 100dvh; }
.app main { flex: 1; overflow: auto; } /* takes the rest; as a scroll container, it can be shorter than its content */
Tested in Chrome: in a 300px column, a 250px item with flex: none and two flex: 1 items, the two share the remaining 50px, at 25px each.
Common patterns
/* a search field that takes the remaining width beside a button */
.search input { flex: 1; min-width: 0; }
.search button { flex: none; }
/* cards that wrap, at least 15rem each, filling the row */
.cards { display: flex; flex-wrap: wrap; gap: 1rem; }
.cards > * { flex: 1 1 15rem; }
/* a sidebar of fixed width and a fluid main area */
.layout { display: flex; gap: 2rem; }
.layout aside { flex: 0 0 14rem; }
.layout main { flex: 1; min-width: 0; }
In the wrapping cards, the last row's cards also grow to fill their line, so a lone last card can be much wider than the others. If the cards should line up in columns, use grid's repeat(auto-fill, minmax(15rem, 1fr)) (article 67).
What's current
flex,flex-grow,flex-shrinkandflex-basiswork in all browsers.flex-basis: contentworks in all browsers.- The automatic minimum size,
min-width: autofor flex items, has been consistent in all browsers for years; it's still the most common flexbox surprise.
Common questions
What's the difference between flex: 1 and flex: auto?
flex: 1 starts every item from 0 and shares all the space, so items come out equal. flex: auto starts from each item's content and only shares what's left, so bigger content stays bigger.
Why won't my flex item shrink below its content?
A flex item's minimum width is auto, its min-content size. Set min-width: 0 (or min-height: 0 in a column).
Why are my flex: 1 items not equal?
One item's content is wider than its share, so its minimum size wins; or the items have different padding or borders, which are added on top of the shared content size.
Should I use width or flex-basis?
On flex items, flex-basis (through flex) is clearer and wins anyway. width still works when the basis is auto.
How do I keep an icon from being squashed?
flex-shrink: 0, or flex: none.
Summary
flex-basisis the starting size along the main axis;autouseswidthor the content.flex-growshares free space in proportion to the grow factors.flex-shrinkremoves overflow in proportion toflex-shrink × flex-basis; the default is 1.- Items don't shrink below their automatic minimum size;
min-width: 0ormin-height: 0removes it. - Use the
flexshorthand:1for equal shares,autofor content-based sizes,nonefor fixed items, or1 1 15remfor a flexible basis.
Practice questions
Two items with the rule below are in an 800px row with no gap. The first has flex-grow: 3. How wide is each?
.item { flex-basis: 200px; flex-grow: 1; }
Answer
The free space is 800 − 400 = 400px, split 3 : 1. The first gets 300px more, and is 500px; the second gets 100px more, and is 300px.
Two items with flex-basis: 300px and flex-shrink: 1 are in a 400px row. One also has flex-shrink: 0. How wide are they?
Answer
The overflow is 200px. The flex-shrink: 0 item keeps 300px, so the other shrinks by all 200px, to 100px, if its content allows it.
A sidebar layout's main area holds a wide <pre> block and pushes the page sideways. The main area has flex: 1. Fix it.
Answer
main { flex: 1; min-width: 0; }
main pre { overflow-x: auto; }
min-width: 0 lets the item shrink below the <pre>'s width, and the <pre> scrolls inside.
What does flex: 10rem set flex-grow, flex-shrink and flex-basis to?
Answer
1 1 10rem. A single length is the basis, and grow and shrink are 1.
Previous: Flexbox Basics: Flex Containers, Axes, flex-direction and flex-wrap
Next: Alignment in Flexbox: justify-content, align-items, gap and auto Margins

More in CSS Course
Quiz: CSS Delicate Details
Twenty-five questions on the edge cases that surprise experienced developers: invalid custom properties, shorthands that reset values, layer order with !important, containing blocks, margin collapsing, specificity of :is() and :where(), intrinsic minimum sizes, and more, each checked in Chrome.
Quiz: CSS Interview Questions
Thirty front-end interview questions: cascade, specificity and layers, box model and margin collapsing, stacking contexts, positioning, flexbox and grid, responsive design, custom properties, performance, accessibility, modern selectors and architecture.
Quiz: CSS Course Final Exam
Thirty questions across the whole CSS course: syntax and error handling, selectors, the cascade and layers, values and units, color, the box model, backgrounds, positioning, flexbox, grid, responsive design, typography, generated content, effects, transforms, motion and architecture.
Quiz: CSS Architecture, Tooling and Debugging (CSS Part 17)
Twenty questions on modular CSS and BEM, layering a stylesheet, design tokens and theming, pattern libraries and safe refactoring, preprocessors and build tools, the at-rules reference, and debugging common CSS problems.
Discussion
Sign in to ask a question or share what you learned.