You're building a layout. A flex child just won't shrink. You've tried flex: 1, overflow: hidden, width: 0 — nothing works. Here's the one property that actually fixes it.
The Setup
I was working on a card layout: a row with an image on the left and a text block on the right. The text block had a long, unbreakable string (a URL, in this case) and it was blowing out the entire card width.
The flex container was set up "correctly":
.card {
display: flex;
gap: 1rem;
}
.card__image {
flex: 0 0 80px;
}
.card__text {
flex: 1;
}
The text child had flex: 1. It should take up the remaining space and shrink if needed. It wasn't. The long string just kept pushing the card wider and wider.
I spent about 45 minutes going in circles before I found the actual cause.
What I Tried First (The Red Herrings)
Here's the trail of dead ends, in order:
1. flex: 1 → didn't help
I kept increasing it, tried flex: 1 1 0% explicitly, even tried flex-grow: 1; flex-shrink: 1; flex-basis: 0. The child still refused to go below its content width.
2. overflow: hidden → masked the problem
This looked like it worked — the text got clipped. But the card was still the wrong size. It was hiding the symptom, not fixing the cause.
3. width: 0 → worked but broke everything else
Forcing width: 0 on the flex child made it shrink, but now the text had no room to render at all. It was a nuclear option.
4. max-width: 100% → no effect
This is what confused me the most. The element was clearly wider than its parent, so max-width: 100% should have capped it. But flexbox sizing rules override this in a way that's not immediately obvious.
At this point I was ready to just use a grid and move on.
The Actual Cause
The culprit is a property you've probably never set on purpose because you didn't know you needed to:
min-width: auto;
This is the default min-width for every flex item. And here's what it actually means in a flex context:
"At minimum, be as wide as my content."
It's not 0. It's not auto in the sense of "let the browser figure it out." It specifically resolves to the item's content size when the item is a flex child.
So the negotiation goes like this:
-
flex: 1says: "I want to shrink to fit available space." -
min-width: autosays: "Nope. Not below my content width. Deal with it."
The min wins. Always.
This is why flex-shrink: 1 (part of the flex: 1 shorthand) has zero effect — the shrink calculation is clamped at min-width before it ever gets applied.
The Fix
One line:
.card__text {
flex: 1;
min-width: 0;
}
That's it. min-width: 0 tells the browser: "Yes, you're allowed to shrink me below my content width."
Now flex: 1 can actually do its job. The child shrinks to fill the available space, and the long string overflows (which you then handle with overflow: hidden + text-overflow: ellipsis if you want a truncation).
Full working example:
.card {
display: flex;
gap: 1rem;
}
.card__image {
flex: 0 0 80px;
}
.card__text {
flex: 1;
min-width: 0; /* ← this is the fix */
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
The Mental Model
Think of flexbox sizing as a negotiation, not a command:
| Property | What it says |
|---|---|
flex-basis |
"This is my starting size" |
flex-grow |
"I can grow beyond that" |
flex-shrink |
"I can shrink below that" |
min-width / min-height
|
"But never below this" |
flex: 1 is shorthand for flex: 1 1 0% — grow, shrink, start at zero. But min-width: auto (the default) sets a floor at content size, so the "start at zero" part is effectively ignored.
The moment you set min-width: 0, you're removing the floor. Now the full flex algorithm can operate.
The same thing applies to the cross axis: if a flex child won't shrink in height, check min-height: auto.
When You'll Actually Need This
You'll hit this pattern in:
-
Text truncation —
text-overflow: ellipsisinside a flex child (the exact case above) - Nested flex/grid layouts — a grid column containing a flex row where the inner child has long unbreakable content
- Sidebar + content layouts — the content area has a long URL, filename, or code snippet
- Table-like layouts in flex — columns that should be fixed-width but contain overflow content
If your flex child "should" be narrower than its content and isn't, min-width: 0 is 90% of the time the answer.
TL;DR
If a flex child won't shrink below its content width, add min-width: 0 to it. The default min-width: auto pins the item to its content size and overrides flex-shrink. One line fixes it.
If this saved you 45 minutes, a clap helps. And if you've hit a different "why won't this shrink" mystery, drop it in the comments — I'll bet it's min-width: auto too.
Top comments (0)