v149 · css
flex-wrap: balance
A new value for flex-wrap that distributes children across lines so each line carries a similar load. The same idea as text-wrap: balance, applied to flex containers — no more long-then-short ragged ends.
concepts
-
Balanced Tags
A tag cloud with mixed-width children. Toggle between
wrapandbalanceand watch the lines settle into roughly equal lengths. -
Container Resizer
One row, a width slider, and a wrap-mode toggle. Live readouts count lines and chips-per-line so you can see exactly when
balancerescues a stranded last-line item. -
Line Load Visualizer
Control item count and average width, then compare wrap vs. balance with bar charts showing how many items land on each line. A numeric imbalance score (max − min line count) makes the improvement measurable.
-
Nav Toolbar
A navigation bar with 11 items of varying widths. Drag the container-width slider and toggle between
wrapandbalanceto see how balance prevents orphaned single-item last rows. Includes a side-by-side comparison with orphan highlighting. -
Chip Editor
Add and remove chips interactively — type your own labels or click presets. An imbalance score updates live as the chip set changes, showing exactly when and how much
balanceimproves the layout overwrap. -
Filter Row
An e-commerce filter panel with category, brand, and price range chips. Toggle between
flex-wrap: wrapandbalanceto see how balance prevents orphaned single chips on the last row — particularly visible in the 11-chip category section.
why it shipped
Default flex-wrap: wrap greedily packs each line to capacity. With variable-width children — tags, chips, button rows — that often leaves the last line lopsidedly short, so the whole block looks unbalanced. The balance value tells the layout algorithm to look at the full set of children and pick a wrap that minimises line-length variance. It matches what text-wrap: balance does for inline text, and it gives flex layouts the visual rhythm authors usually want.
references
implementation reference
Need the exact API surface, compatibility boundaries, errors, lifecycle, and source links? Read the matching gendn reference ↗