Web development

Let long content shrink inside a flex row

Give a flexible text child min-width zero when its intrinsic minimum size prevents a flex row from shrinking. Add an explicit wrapping policy for unusually long tokens.

Worked example

HTML example · save as example.html and open in a browser

<style>
.row{display:flex;gap:1rem;max-width:22rem;border:1px solid #aaa;padding:1rem}
.text{min-width:0;overflow-wrap:anywhere}
.icon{flex:none}
</style>
<div class="row"><span class="icon">File</span><span class="text">a_very_long_filename_without_normal_break_points.json</span></div>

How it works

The icon keeps its natural width, while the text item can shrink into the remaining space. Overflow-wrap permits breaks within a token when normal break opportunities are insufficient. This is helpful for filenames and URLs in constrained rows.

Limits and mistakes

Breaking any word can hurt readability for ordinary prose, so apply the rule where long tokens are expected. Min-width zero is not an instruction to truncate; if truncation is wanted, provide a way to access the complete value.

Check the result

Reduce the container width and verify the filename wraps without pushing the icon or expanding the page. Test ordinary words too, so the fix does not create awkward wrapping everywhere.

Sources

Reference documentation for the behavior used in this guide: