Skip to content
Preptima
mediumConceptScenarioEntryMidSenior

A flex item with a long URL in it pushes past its container instead of shrinking. Why does flex-shrink not save you?

Flex items default to min-width: auto, which stops them shrinking below their min-content width, and an unbroken URL makes that width the whole URL. flex-shrink only shares out space above that floor. Set min-width: 0 on the item and give the text a break point with overflow-wrap: anywhere; in grid, use minmax(0, 1fr).

4 min readUpdated 2026-10-09Target archetype: Big Tech, Product Startup

Answer

Short answer

The item cannot shrink below its own floor. Flex items default to min-width: auto, which resolves to their min-content width, and an unbroken URL makes that width as long as the URL. flex-shrink only distributes space above that floor, so the fix for flexbox overflow is to lower the floor with min-width: 0 on the item and give the URL somewhere to break.

.card-body {            /* the flex item, not the link inside it */
  min-width: 0;         /* release the min-content floor */
}
.card-body a {
  overflow-wrap: anywhere; /* lets the URL wrap, and shrinks min-content too */
}

Was this answer helpful?

Likely follow-ups

  • Two columns declared as flex: 1 come out at different widths once one of them holds a long code sample. Why does a zero flex-basis not equalise them?
  • Text-overflow ellipsis on a filename inside a flex row never shows the ellipsis. Which three declarations does it need, and on which elements?
  • You fixed the overflow with overflow: hidden on the flex item and a dropdown inside it is now clipped. What would you have done instead?
  • When would you rather keep the automatic minimum and let the row wrap, instead of letting the item shrink?

Related questions

Further reading