Truncating in the middle with Flexbox and text-overflow
Making a single line of text end in an ellipsis (…) is a simple job for text-overflow plus a couple of companion properties. The catch is placement: the cut always lands at the end of the line. Truncating somewhere in the middle takes a different approach.
Where middle truncation pays off
Leonardo Faria has documented cases where this matters, such as file listings in an operating system window. There the line combines a file name with its extension. When space runs out, only the name gets trimmed, and the extension stays visible at the end.
Why the flex parent needs a min-width reset
The mechanism is a flexbox parent that lets overflow apply to just the name portion. One adjustment is required: the min-width on that child must be reset. Its natural min-content value otherwise blocks the truncation, a behavior that often confuses people.
- Truncation via
text-overflowhandles line ends, not middles. - A flex parent is what allows overflow on one segment of the line.
- Reset
min-widthaway from itsmin-contentdefault or nothing gets truncated.



