Learn CSS Visually - CSS explained one diagram at a time - flexbox, grid, the box model and more

flex-grow, flex-shrink and flex-basis Made Visual

By · Updated

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.

Diagram drawn to scale of a 600 pixel flex container holding three items with flex-basis 100px and 300 pixels of free space; with flex-grow 1 1 1 each item grows by 100 pixels to 200, with flex-grow 1 1 2 the items grow by 75, 75 and 150 pixels, and with flex-grow 0.25 on each item they grow by 75 pixels each and 75 pixels of the container stay empty.
flex-grow in one picture: every item starts at its flex-basis (orange), then the free space (blue) is cut into shares and handed out (green).

What the diagram shows, in plain text (600px container, three items with flex-basis: 100px, so 300px of free space):

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 from width (in a row), or from the content when width is also auto.

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-width and max-width still win. The spec’s sizing steps clamp every flex item by its minimum and maximum size after growing or shrinking, so max-width: 250px stops a growing item at 250px whatever its flex-grow.
  • Padding can add to it. The spec notes that flex-basis determines the size of the content box, unless otherwise specified such as by box-sizing. With box-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 in a 600px container with three items of flex-basis: 100px (300px of free space) — calculated by Learn CSS Visually with the W3C Flexbox spec’s 9.7 steps, November 16, 2026
flex-grow on items 1, 2, 3Sum of factorsFree space handed outEach item gainsFinal widths
1, 1, 13300px100 / 100 / 100px200 / 200 / 200px
2, 2, 26300px100 / 100 / 100px200 / 200 / 200px (only the ratio counts)
1, 1, 24300px75 / 75 / 150px175 / 175 / 250px
0, 1, 01300px0 / 300 / 0px100 / 400 / 100px
.25, .25, .250.75225px (75% of it)75 / 75 / 75px175 / 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.

To-scale diagram of a 500 pixel flex container with three items whose flex-basis is 300, 200 and 100 pixels, 100 pixels too wide: with flex-shrink 0 they overflow by 100 pixels, with the default flex-shrink 1 they shrink to 250, 166.7 and 83.3 pixels, with flex-shrink 0 on the first item the others shrink to 133.3 and 66.7, and with a min-width of 80 pixels on the third item the widths end at 300, 120 and 80.
flex-shrink in one picture: the overflow is taken from each item in proportion to its size, rigid items (flex-shrink: 0) keep their basis, and min-width sets a floor.

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: 0 on all three — nothing shrinks; the row overflows the container by 100px.
  • flex-shrink: 1 on 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: 80px on 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 in a 500px container with items of flex-basis 300, 200 and 100px (100px of overflow) — calculated by Learn CSS Visually with the W3C Flexbox spec’s 9.7 steps, November 16, 2026
flex-shrink on items 1, 2, 3Scaled factors (flex-shrink x basis)Each item losesFinal widths
1, 1, 1 (default)300 / 200 / 100 (sum 600)50 / 33.3 / 16.7px250 / 166.7 / 83.3px
1, 1, 3300 / 200 / 300 (sum 800)37.5 / 25 / 37.5px262.5 / 175 / 62.5px
0, 1, 1- / 200 / 100 (sum 300)0 / 66.7 / 33.3px300 / 133.3 / 66.7px
0, 1, 1 + min-width: 80px on item 3pass 1 as above; item 3 is clamped to 80px and frozen; pass 2 puts the last 80px of overflow on item 20 / 80 / 20px300 / 120 / 80px
0, 0, 0none0 / 0 / 0px300 / 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.

To-scale diagram of three flex items whose content is 50, 100 and 150 pixels wide in a 600 pixel container: by default they keep those widths with 300 pixels free, with flex auto each grows by 100 to 150, 200 and 250 pixels, with flex 1 they are all 200 pixels, with flex 1 and a long unbreakable URL in the third item its min-content width of 320 pixels leaves 140 pixels for the others, and adding min-width 0 makes them equal again.
flex: auto shares the free space on top of the content size; flex: 1 shares all of the space from zero — until an automatic minimum size gets in the way.

The same comparison as numbers:

flex: auto vs flex: 1 in a 600px container, items with 50, 100 and 150px of content — calculated by Learn CSS Visually with the W3C Flexbox spec’s 9.7 steps, November 16, 2026
Setting on the itemsItem 1Item 2Item 3
default (flex: 0 1 auto)50px100px150px (300px left over)
flex: auto (1 1 auto)150px200px250px
flex: 1 (1 1 0)200px200px200px
flex: 1, item 3 holds a 320px-wide unbreakable URL140px140px320px (its minimum)
flex: 1 + min-width: 0200px200px200px (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):

The flex shorthand expanded — compiled by Learn CSS Visually from the W3C Flexbox spec, sections 7.1 and 7.1.1, November 16, 2026
You writeflex-growflex-shrinkflex-basisWhat it does
nothing, or flex: initial01autocontent size; shrinks only when the row is too tight
flex: auto11autogrows from the content size; bigger content stays bigger
flex: none00autorigid: never grows, never shrinks
flex: 1110equal shares of the whole container
flex: 2210twice the width of a flex: 1 sibling
flex: 200px11200pxstarts at 200px, then grows or shrinks
flex: 1 1 220px11220pxwrapping cards about 220px wide that share the rest
flex: 0 0 240px00240pxa fixed 240px sidebar
flex: 1 0100careful: 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:

  1. A long word, URL, image or table. The automatic minimum size holds that item open. Add min-width: 0 to the items, and let the content wrap or scroll.
  2. Padding or borders that differ. flex-basis sizes the content box, so an item with 40px of padding ends up 40px wider. Use box-sizing: border-box (the box model guide draws the difference), or give every item the same padding.
  3. A min-width, max-width or width on one item. Min and max clamp the result; a width only matters if something has turned the basis back to auto.
  4. Different flex values. A later rule may set flex: auto or flex-grow: 2 on one item. Check the computed flex-grow, flex-shrink and flex-basis in DevTools.
  5. 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-grow and flex-shrink
Chrome 29, Edge 12, Firefox 20, Safari 9 (unprefixed)
flex-basis
Chrome 29, Edge 12, Firefox 22, Safari 9
flex shorthand
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

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.

How this was written: Written from the W3C CSS Flexible Box Layout Module Level 1 (Candidate Recommendation Draft, 14 October 2025) — sections 4.5 (automatic minimum size), 7 (flexibility) and 9.7 (resolving flexible lengths) — MDN Web Docs’ Controlling ratios of flex items guide and its flex-grow, flex-shrink and flex-basis references, the flexbox module of web.dev’s Learn CSS course, the Firefox DevTools Flexbox Inspector docs, MDN’s browser-compat-data and the Can I use support data (updated November 11, 2026), all read on November 16, 2026. Every width in the diagrams and tables is our own work, calculated by following the spec’s 9.7 steps (items with no padding, border or margin). Code samples are simplified for learning.

Oh, one more thing…

If this helped, you’ll like our free updates: the insights we discover while researching, and the moments worth sharing with other people learning CSS — no spam, no promotions.

One short email when there’s something worth your time. Unsubscribe any time.