How can I stop a long word from stretching a grid or flex layout?
Quick answer
A long unbroken string can affect an item’s minimum size and make a grid or flex layout wider than expected. Try min-width: 0 on the grid or flex item to let it shrink, and overflow-wrap: anywhere on the text to let an overlong word break. These solve different parts of the problem, so use both when needed and check that the text remains readable. [S1] [S2]
The question, the details, the next step.
A practical checklist
Identify the grid or flex item that is expected to shrink.
Add
min-width: 0to that item and check whether it can become narrower.Apply
overflow-wrap: anywhereto the text containing the unbroken value if it still spills out.Check the layout at the narrow widths where the problem occurs.
Confirm that the value remains readable and is not merely clipped or hidden.
A few more useful answers
Does `min-width: 0` make a long word wrap?
Should I put `overflow-wrap: anywhere` on the whole page?
Start with the specific text container that has the problem. A focused change makes it easier to assess whether breaking that particular content is readable.
Why does the problem remain after adding `min-width: 0`?
Sources
References used for this guide.
- [S1] Wrapping and breaking text — CSS | MDN developer.mozilla.org · Checked
- [S2] min-width — CSS | MDN developer.mozilla.org · Checked
