C.W.K.
Stream
Lesson 03 of 04 · published

flex-grow, flex-shrink, flex-basis: The Sizing Triple

~11 min · flex-grow, flex-shrink, flex-basis, flex-shorthand

Level 0Markup Novice
0 XP0/34 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete
"flex is one property that's actually three. Memorize the three patterns and you're done."

The Three Sub-Properties

Every flex child has three properties that decide its size:

  • flex-grow (default 0) — share of extra space along the main axis. flex-grow: 1 takes 1/total-grow of leftover space.
  • flex-shrink (default 1) — share of overflow reduction. flex-shrink: 1 means the item shrinks when there's not enough room; flex-shrink: 0 means it refuses to shrink.
  • flex-basis (default auto) — the starting size before grow/shrink calculations. auto means "use the item's content size or its width property"; a length like 200px means "start at 200px regardless of content."

The flex Shorthand

flex: <grow> <shrink> <basis>. Three values, in that order. Examples:

  • flex: 1 1 0 — grow 1, shrink 1, start at 0. All siblings with this become equal-width.
  • flex: 1 1 auto — grow 1, shrink 1, start at content/auto size. All siblings with this get proportional shares based on their content.
  • flex: 0 0 200px — no grow, no shrink, fixed 200px. Locked in.
  • flex: 0 1 auto — the default for a flex child. Content size, shrinks if needed, doesn't grow.

The Three Patterns You'll Use 95% Of The Time

  • flex: 1 — shorthand for 1 1 0. Equal-share. Pattern: "all these siblings should split the available space evenly."
  • flex: auto — shorthand for 1 1 auto. Content-proportional share. Pattern: "these items should share extra space, but their content sizes matter as a starting point."
  • flex: none — shorthand for 0 0 auto. Don't grow, don't shrink. Pattern: "this item should stay exactly its content size."

Memorize these three. They cover almost every layout you'll write. Reach for the explicit three-value form (flex: 1 1 200px) when you need precision.

The Equal-Width Columns Pattern

Want three columns to share the row equally regardless of content? flex: 1 on each. Want three columns where one is 300px and the other two split the rest equally? flex: 0 0 300px on the first, flex: 1 on the others.

The Sidebar + Main Pattern

Fixed-width sidebar with flexible main content area:

Or — and more idiomatic in 2026 — use Grid: grid-template-columns: 240px 1fr. Same effect, less typing. Flexbox is still correct here; Grid is just more declarative for two-column patterns.

The Default min-width: auto Pitfall

Flex items have an implicit min-width: auto, which roughly means "don't shrink below the size of the longest unbreakable content (a long word, an image's intrinsic size)." This is usually helpful but occasionally causes mysterious overflow: a flex row containing a child with a long URL or unbreakable text refuses to shrink the child, pushing the row past the container.

The fix: min-width: 0 on the flex child that should be allowed to shrink. This explicit override removes the implicit minimum and lets flex-shrink do its job. Most common in chat UIs (long pasted URLs) and tables-as-flex.

If a flex row mysteriously overflows because of one child, suspect the implicit min-width: auto. Add min-width: 0 to the offending child. This single fix saves more time than knowing all the rest of flexbox combined.

Order: The Source-Order Reorderer

The order property on a flex child changes its visual position without changing source order. Default is 0; lower values come first, higher last. Pattern: a card with a label at the top of the visual layout but at the bottom of source order (for SEO/accessibility), use order: -1 on the label.

Use sparingly. order can confuse screen reader users (who read in source order) and keyboard users (whose Tab order follows source). Reorder visually only when source order would be wrong for non-visual reasons (semantics, document structure).

Pippa's Note

Pippa's chat composer is a flex row: textarea on the left (flex: 1 — fills the available width), send button on the right (flex: none — fixed icon size). Three lines of CSS. The conversation list is a flex column where every conversation row is flex: 0 0 auto (don't grow, don't shrink, take content size), with a min-width: 0 on the row's title so a long conversation title truncates with text-overflow: ellipsis instead of pushing the row wider.

Code

The three shorthand forms·css
/* Three patterns to memorize */

/* Equal-share: all children take the same width */
.equal-row > * { flex: 1; }              /* = 1 1 0 */

/* Content-proportional: children share but content matters */
.content-row > * { flex: auto; }         /* = 1 1 auto */

/* Fixed: this child doesn't grow or shrink */
.fixed-item { flex: none; }              /* = 0 0 auto */
Sidebar + main, two ways·css
/* Sidebar + main with Flexbox */
.layout {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  flex: 0 0 240px;       /* fixed 240px, won't grow or shrink */
}
.main {
  flex: 1;               /* takes the rest */
  min-width: 0;          /* allow shrink past intrinsic content (avoids overflow) */
}

/* Same layout with Grid (often cleaner) */
.layout-grid {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
min-width: 0 — the most useful flex incantation·css
/* The implicit min-width: auto trap */

.row {
  display: flex;
  gap: 1rem;
  width: 500px;            /* parent has a fixed width */
}
.row > .title {
  flex: 1;                 /* should shrink to share */
}

/* But if .title contains a long word or unbreakable URL, it refuses
   to shrink past the word's intrinsic width — even though flex-shrink
   is 1. The implicit min-width: auto prevents the shrink. */

.row > .title {
  flex: 1;
  min-width: 0;            /* explicit override — now the title shrinks */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;     /* combine with min-width: 0 for ellipsis */
}

/* This three-line addition is the standard pattern for any flex child
   that contains arbitrary text and must truncate gracefully */

External links

Exercise

Build three layouts: (1) three equal-width columns with flex: 1 (verify they're equal in DevTools); (2) one fixed 200px sidebar + two flexible columns that share the rest equally; (3) a chat row with an avatar (flex: none, 40px), a name and message taking the remaining width (flex: 1, min-width: 0, text truncation), and a timestamp (flex: none, auto width). Test each by making the parent narrower and confirming the right things shrink or truncate.
Hint
For #3, paste a very long URL into the message text and confirm it truncates with ellipsis rather than pushing the row wider. If it pushes wider, you forgot min-width: 0 on the flex: 1 child.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.