flex-grow, flex-shrink and flex-basis Made Visual
Disclosure: this page contains Amazon affiliate links. As an Amazon Associate we earn from qualifying purchases, at no extra cost to you.
Hi there, flex fiddler! flex-grow, flex-shrink and flex-basis are the three little numbers that decide how wide every flex item ends up, and the whole secret is that the browser starts from a size, then shares out whatever room is left over (or missing).
These three properties decide how wide every flex item ends up, and once you see them as a starting size, then share the leftovers
, they stop feeling random.
If you like a printed reference beside the keyboard, the CSS Visual Dictionary paperback on Amazon draws the flex properties as pictures too.
Short answer: flex-basis sets a flex item’s starting size, flex-grow decides how much of the leftover space it takes, and flex-shrink decides how much it gives up when the row is too tight. The defaults are 0, 1 and auto: items keep their size, never grow, and shrink when needed. flex: 1 means 1 1 0.
What the diagram shows, in plain text (600px container, three items with flex-basis: 100px, so 300px of free space):
flex-grow: 1on all three — 3 equal shares of 100px — final widths 200 / 200 / 200px.flex-grow: 1, 1, 2— 4 shares of 75px — the items grow by 75, 75 and 150px — final widths 175 / 175 / 250px.flex-grow: .25on all three — each takes 25% of the free space, 75px — final widths 175 / 175 / 175px, with 75px left empty.
What do flex-grow, flex-shrink and flex-basis do?
flex-basis is a flex item’s starting size, flex-grow is its share of any spare room, and flex-shrink is its share of the cut when the items don’t fit.
The browser always works in that order: first it lays every item out at its basis, then it measures what’s left, then it grows or shrinks the items to fill the line exactly.
MDN Web Docs’ Controlling ratios of flex items guide sums the two factors up as questions: How much of the positive free space does this item get?
for flex-grow, and How much negative free space can be removed from this item?
for flex-shrink.
Positive free space is room left over; negative free space is how far the items overflow.
The default values, from the property tables in the W3C CSS Flexible Box Layout Module Level 1 (Candidate Recommendation Draft, 14 October 2025):
flex-grow- initial value
0— flex items don’t grow unless you ask. Negative values aren’t allowed. flex-shrink- initial value
1— flex items do shrink when the line is too tight. Negative values aren’t allowed. flex-basis- initial value
auto— the starting size comes fromwidth(in a row), or from the content whenwidthis alsoauto.
All three only work on flex items — the direct children of an element with display: flex or inline-flex.
If the main axis and cross axis are new to you, our flexbox explainer draws them first; everything on this page happens along the main axis.
What is flex-basis?
flex-basis is the size a flex item starts from before any growing or shrinking. The W3C spec defines it as the initial main size of the flex item, before free space is distributed according to the flex factors
.
In a row, that’s a starting width; in a column (flex-direction: column), the same flex-basis sets a starting height.
.item { flex-basis: 200px; } /* start at 200px, then grow or shrink */
.item { flex-basis: 25%; } /* 25% of the flex container's inner width */
.item { flex-basis: auto; } /* use width - or the content if width is auto */
Is flex-basis the same as width?
No — in a flex row, a flex-basis other than auto wins over width, and width only matters when flex-basis is auto.
The spec says the auto keyword retrieves the value of the main size property as the used flex-basis
— so flex-basis: auto plus width: 300px starts the item at 300px, but flex-basis: 200px plus width: 300px starts it at 200px.
Three things still apply on top of flex-basis:
min-widthandmax-widthstill win. The spec’s sizing steps clamp every flex item by its minimum and maximum size after growing or shrinking, somax-width: 250pxstops a growing item at 250px whatever itsflex-grow.- Padding can add to it. The spec notes that
flex-basisdetermines the size of the content box, unless otherwise specified such as by box-sizing
. Withbox-sizing: border-box, the padding and border fit inside the basis instead. - Percentages use the container.
flex-basis: 25%is 25% of the flex container’s inner main size — and if the container’s size isn’t known yet, the browser falls back to the content size.
What’s the difference between flex-basis auto, content and 0?
flex-basis: auto uses the item’s width (or height in a column), content always uses the size of what’s inside, and 0 starts the item from nothing so all of the room becomes free space.
When width is auto too, auto and content give the same result — the spec says that if the main size is itself auto, then the used value is content
, which is typically the item’s max-content width (its text laid out on one line).
content is the newcomer: the spec notes it was not present in the initial release of Flexible Box Layout
. MDN’s browser-compat-data lists flex-basis: content from Chrome 94, Edge 94, Firefox 61 and Safari 15.4.
A zero basis is the one you’ll use most, because it’s what flex: 1 sets — more on that in the flexbox basics and in the flex: 1 section below.
How does flex-grow share out the free space?
flex-grow splits the free space in proportion to each item’s number: add up the flex-grow values on the line, divide the free space by that total, and give each item its number of shares.
An item with flex-grow: 2 gets twice the extra room of an item with flex-grow: 1 — twice the extra, not twice the width.
That last part trips people up. In the diagram at the top, the item with flex-grow: 2 ends at 250px and its neighbours at 175px: it got 150px of extra room against their 75px, but because they all started at 100px, it’s nowhere near twice as wide.
To get widths in a true 1 : 1 : 2 ratio, start every item from zero with flex: 1, flex: 1 and flex: 2.
.row { display: flex; width: 600px; }
.item { flex-basis: 100px; flex-grow: 1; }
.item.wide { flex-grow: 2; } /* gets 2 shares of the free space */
How do you calculate flex-grow widths?
To calculate a flex-grow width, take the free space (container width minus every item’s basis), divide it by the sum of the flex-grow values, and add that many shares to each item’s basis. Here are five setups worked out in pixels:
| flex-grow on items 1, 2, 3 | Sum of factors | Free space handed out | Each item gains | Final widths |
|---|---|---|---|---|
1, 1, 1 | 3 | 300px | 100 / 100 / 100px | 200 / 200 / 200px |
2, 2, 2 | 6 | 300px | 100 / 100 / 100px | 200 / 200 / 200px (only the ratio counts) |
1, 1, 2 | 4 | 300px | 75 / 75 / 150px | 175 / 175 / 250px |
0, 1, 0 | 1 | 300px | 0 / 300 / 0px | 100 / 400 / 100px |
.25, .25, .25 | 0.75 | 225px (75% of it) | 75 / 75 / 75px | 175 / 175 / 175px, 75px left empty |
The 0, 1, 0 row is the classic this one item takes all the remaining space
layout — a search box that stretches between a logo and a button, for example.
What does flex-grow below 1 do?
When the flex-grow values on a line add up to less than 1, the items don’t use all the free space — each gets exactly its fraction and the rest stays empty.
The spec explains it with this very example: three items with flex-grow: .25 get 25% of the free space to each, with the final 25% left unfilled
.
The spec also gives some friendly advice: authors should stick to values ≥ 1; for example, using 1 and 2 is usually better than using .33 and .67
, because whole numbers keep behaving as intended when items are added, removed or wrapped onto a new line.
How does flex-shrink decide which item shrinks?
flex-shrink removes the overflow in proportion to each item’s flex-shrink value multiplied by its flex-basis — so with the default flex-shrink: 1, a big item gives up more pixels than a small one.
That’s the big difference from flex-grow, which hands out space by the factor alone.
What the diagram shows, in plain text (500px container, items with flex-basis 300, 200 and 100px — 600px of items, 100px too wide):
flex-shrink: 0on all three — nothing shrinks; the row overflows the container by 100px.flex-shrink: 1on all three (the default) — the items lose 50, 33.3 and 16.7px — final widths 250 / 166.7 / 83.3px.flex-shrink: 0, 1, 1— item 1 stays at 300px; items 2 and 3 lose 66.7 and 33.3px — final widths 300 / 133.3 / 66.7px.- The same, plus
min-width: 80pxon item 3 — item 3 stops at 80px and item 2 takes the rest of the cut — final widths 300 / 120 / 80px.
Why does the bigger flex item shrink more?
The bigger flex item shrinks more because the browser weights each item’s flex-shrink by its size before sharing out the overflow. The W3C spec puts the reason in a note:
The flex shrink factor is multiplied by the flex base size when distributing negative space. This distributes negative space in proportion to how much the item is able to shrink, so that e.g. a small item won’t shrink to zero before a larger item has been noticeably reduced.
The spec’s algorithm calls the result the scaled flex shrink factor
. With equal flex-shrink values, every item loses the same percentage of its own basis — in our example, each one loses one sixth. Here’s the math for five setups:
| flex-shrink on items 1, 2, 3 | Scaled factors (flex-shrink x basis) | Each item loses | Final widths |
|---|---|---|---|
1, 1, 1 (default) | 300 / 200 / 100 (sum 600) | 50 / 33.3 / 16.7px | 250 / 166.7 / 83.3px |
1, 1, 3 | 300 / 200 / 300 (sum 800) | 37.5 / 25 / 37.5px | 262.5 / 175 / 62.5px |
0, 1, 1 | - / 200 / 100 (sum 300) | 0 / 66.7 / 33.3px | 300 / 133.3 / 66.7px |
0, 1, 1 + min-width: 80px on item 3 | pass 1 as above; item 3 is clamped to 80px and frozen; pass 2 puts the last 80px of overflow on item 2 | 0 / 80 / 20px | 300 / 120 / 80px |
0, 0, 0 | none | 0 / 0 / 0px | 300 / 200 / 100px — 100px overflows |
The fourth row shows the loop the spec describes in section 9.7: the browser shrinks, checks every item against its min-width and max-width, freezes any item that hit a limit, and shares out what’s left again until everything fits.
What does flex-shrink: 0 do?
flex-shrink: 0 stops a flex item from shrinking below its flex-basis, so the other items take the whole cut — or the row overflows if they can’t. It’s the fix for icons, avatars and buttons that get squashed in a tight row.
.avatar { flex-shrink: 0; width: 48px; } /* never squashed */
.logo { flex: none; } /* 0 0 auto: never grows or shrinks */
Why won’t my flex item shrink?
A flex item usually won’t shrink because of its automatic minimum size: by default a flex item can’t get narrower than its longest word, a long URL, a wide image or a wide child.
Add min-width: 0 to the item (or min-height: 0 in a column), and it can shrink past its content.
The W3C spec says it plainly: By default, flex items won’t shrink below their minimum content size (the length of the longest word or fixed-size element). To change this, set the min-width or min-height property.
MDN’s guide makes the same point: Small items will not shrink to less than their min-content size
.
.main {
flex: 1;
min-width: 0; /* allow shrinking past long content */
}
.main pre, .main table {
overflow-x: auto; /* the wide child scrolls instead */
}
What does flex: 1 mean?
flex: 1 means flex-grow: 1, flex-shrink: 1 and flex-basis: 0: the item starts from zero and takes an equal share of all the space in the container.
Real talk: flex: 1 felt like a magic spell to me for ages — one tiny number and suddenly three columns behave. Knowing it quietly means 1 1 0 is what turns the spell into plain arithmetic you can actually reason about (and fix when it misbehaves).
The spec explains why the shorthand fills in different values from the longhand defaults: when you leave parts out, they act like 1 1 0px
, so that the flex shorthand can better accommodate the most common cases
.
web.dev’s Learn CSS flexbox module puts the effect in one sentence:
Using flex: 1 says that all items have zero size, therefore all of the space in the flex container is available to be distributed.
The spec also recommends the shorthand over the three longhands, because it correctly resets any unspecified components to accommodate common uses
.
What’s the difference between flex: 1 and flex: auto?
flex: 1 starts every item from zero, so the items end up equal; flex: auto starts every item from its content size, so items with more content stay wider. Both grow and shrink — only the starting point (the flex-basis) is different.
The same comparison as numbers:
| Setting on the items | Item 1 | Item 2 | Item 3 |
|---|---|---|---|
default (flex: 0 1 auto) | 50px | 100px | 150px (300px left over) |
flex: auto (1 1 auto) | 150px | 200px | 250px |
flex: 1 (1 1 0) | 200px | 200px | 200px |
flex: 1, item 3 holds a 320px-wide unbreakable URL | 140px | 140px | 320px (its minimum) |
flex: 1 + min-width: 0 | 200px | 200px | 200px (wrap the URL with overflow-wrap: anywhere) |
web.dev’s flexbox module describes the flex: auto row the same way: items end up different sizes, as the space that is shared between the items is shared out after each item is laid out as max-content size
.
What do flex: none, flex: initial and flex: 0 0 200px do?
Each flex value is just three numbers in disguise — grow, shrink and basis. This cheat sheet expands the common ones, following the spec’s shorthand rules (a missing grow or shrink becomes 1, a missing basis becomes 0):
| You write | flex-grow | flex-shrink | flex-basis | What it does |
|---|---|---|---|---|
nothing, or flex: initial | 0 | 1 | auto | content size; shrinks only when the row is too tight |
flex: auto | 1 | 1 | auto | grows from the content size; bigger content stays bigger |
flex: none | 0 | 0 | auto | rigid: never grows, never shrinks |
flex: 1 | 1 | 1 | 0 | equal shares of the whole container |
flex: 2 | 2 | 1 | 0 | twice the width of a flex: 1 sibling |
flex: 200px | 1 | 1 | 200px | starts at 200px, then grows or shrinks |
flex: 1 1 220px | 1 | 1 | 220px | wrapping cards about 220px wide that share the rest |
flex: 0 0 240px | 0 | 0 | 240px | a fixed 240px sidebar |
flex: 1 0 | 1 | 0 | 0 | careful: here the 0 is flex-shrink, not the basis |
Why aren’t my flex: 1 items equal widths?
When flex: 1 items come out unequal, one of the items almost always has a minimum or extra size that the free space can’t override. Check these five things in order:
- A long word, URL, image or table. The automatic minimum size holds that item open. Add
min-width: 0to the items, and let the content wrap or scroll. - Padding or borders that differ.
flex-basissizes the content box, so an item with 40px of padding ends up 40px wider. Usebox-sizing: border-box(the box model guide draws the difference), or give every item the same padding. - A
min-width,max-widthorwidthon one item. Min and max clamp the result; awidthonly matters if something has turned the basis back toauto. - Different flex values. A later rule may set
flex: autoorflex-grow: 2on one item. Check the computedflex-grow,flex-shrinkandflex-basisin DevTools. - Margins or
gap. These come off the container width before the sharing starts, which is fine — the items are still equal to each other, just narrower than you expected.
Which flex values should you use for common layouts?
For most layouts you only need four flex values: flex: 1 for “fill the space”, flex: none for don’t touch my size
, flex: 0 0 <size> for a fixed column, and flex: 1 1 <size> for wrapping cards. Here they are in context:
/* Fixed sidebar + fluid content */
.sidebar { flex: 0 0 240px; }
.content { flex: 1; min-width: 0; }
/* Three equal columns */
.col { flex: 1; min-width: 0; }
/* Search bar: the input stretches, the button keeps its size */
.search input { flex: 1; min-width: 0; }
.search button { flex: none; }
/* Wrapping cards, about 220px each */
.cards { display: flex; flex-wrap: wrap; gap: 16px; }
.card { flex: 1 1 220px; }
One thing to know about the wrapping cards: each row shares its own free space, so a last row with fewer cards stretches them wider. If you want every card the same width in every row, our flexbox vs Grid guide draws the difference and shows the Grid version.
And to push one item to the far end of a row instead of growing it, use margin-left: auto — our justify-content vs align-items guide covers that trick.
How can you see flex-grow and flex-shrink at work in DevTools?
Firefox shows the whole sizing story for any flex item: select the item in the Inspector and open the Layout panel.
The Firefox Flexbox Inspector draws the item’s content size, a “Flexibility” bar for how much a flex item grew or shrunk
, and a “Minimum Size” marker that only appears when the item is clamped to its minimum — exactly the min-width: 0 situation above.
In Chrome and Edge, click the flex badge next to the container in the Elements panel to see the item outlines, and use the Chrome DevTools flexbox editor for the container’s alignment. For the item’s final width, select it and read the Computed tab.
Do flex-grow, flex-shrink and flex-basis work in every browser?
Yes — flex-grow, flex-shrink, flex-basis and the flex shorthand work in every current browser; only the newer flex-basis keywords like content need a check.
Can I use (data updated November 11, 2026) puts full flexbox support at 97.4% of users worldwide. The versions below are from MDN’s browser-compat-data, read on November 16, 2026:
flex-growandflex-shrink- Chrome 29, Edge 12, Firefox 20, Safari 9 (unprefixed)
flex-basis- Chrome 29, Edge 12, Firefox 22, Safari 9
flexshorthand- Chrome 29, Edge 12, Firefox 22, Safari 9
flex-basis: content- Chrome 94, Edge 94, Firefox 61, Safari 15.4
flex-basis: min-content/max-content- Chrome 94, Edge 94, Firefox 66, Safari 16
Grab three boxes, give them flex-basis: 100px, and play with flex-grow in DevTools until the pixel math on this page feels obvious. Then drop a long URL into one and watch min-width: 0 rescue it. That little moment of “oh, THAT’s why” is the best part of learning CSS.
Sources and further reading
- W3C: CSS Flexible Box Layout Module Level 1, section 7 Flexibility — Candidate Recommendation Draft, 14 October 2025: flex, flex-grow, flex-shrink, flex-basis
- W3C: CSS Flexbox, 9.7 Resolving Flexible Lengths — the step-by-step sizing loop our tables follow
- W3C: CSS Flexbox, 4.5 Automatic Minimum Size of Flex Items — why flex items won’t shrink below their content
- MDN Web Docs: Controlling ratios of flex items along the main axis — positive and negative free space
- MDN Web Docs: flex — the shorthand and its keyword values
- MDN Web Docs: flex-basis — values, including content
- web.dev Learn CSS: Flexbox — flex: auto vs flex: 1
- Firefox DevTools: Examine Flexbox layouts — the Flexbox Inspector’s item sizing panel
- MDN browser-compat-data — browser versions, read November 16, 2026
- Can I use: CSS Flexible Box Layout Module — support data updated November 11, 2026
Questions and answers
What is the difference between flex-grow and flex-shrink?
flex-grow decides how much of the leftover space a flex item takes when the items are smaller than the container; flex-shrink decides how much it gives up when they are too big. Only one of them is used at a time, depending on whether the line has spare room or overflows.
Should I use flex-basis or width in flexbox?
Use flex-basis (usually through the flex shorthand) for the starting size of a flex item, because it follows the main axis in both rows and columns. In a row, a flex-basis other than auto overrides width, while min-width and max-width still apply.
What does flex: 1 1 0 mean?
It means flex-grow: 1, flex-shrink: 1 and flex-basis: 0 — exactly what flex: 1 expands to. Every item starts from zero, so all of the container’s space is shared out equally between the items with the same value.
How do I make a flex item fill the remaining space?
Give that one item flex: 1 (or flex-grow: 1) and leave the others at the default. The other items keep their natural size, and the free space all goes to the item with flex-grow: 1.
Why is flex-shrink: 0 not working?
The usual cause is a flex shorthand later in the CSS, such as flex: 1, which resets flex-shrink to 1. Also check that the element really is a direct child of a flex container, and remember that with flex-basis: 0 there is nothing to keep — give it a basis or width to hold.