Headings Keep Stranding One Word? text-wrap: balance and pretty Fix It
October 14, 2026 · 7 min read · CSS
By Syed · Frontend Engineer & Creator of UITweak
You know the sight. A headline that reads "Introducing the new dashboard for" and then "teams" sitting alone on the next line, like it missed the bus. Or a paragraph that ends with a single widow word dangling at the bottom. Designers notice it instantly, and the fixes we have used for years are all broken in their own way. Two CSS declarations fix it natively, and most sites still do not use them: the CSS text-wrap: balance value for headings, and text-wrap: pretty for paragraphs.
30-second version: text-wrap: balance spreads heading text evenly across lines, and text-wrap: pretty stops paragraphs from ending on a lone word. Two lines cover your whole site: h1, h2, h3, h4 { text-wrap: balance; } and p, li { text-wrap: pretty; }. Unsupported browsers fall back to normal wrapping with zero breakage.
Why browsers strand words in the first place
Browsers wrap text greedily: each line takes as many words as fit, then breaks, then repeats. That is fast, but it is a line-by-line decision, and the last line pays for it. A headline that fits in two lines will happily leave one word alone on line two, because no line looked at the whole block before breaking.
balance and pretty change the strategy. Instead of breaking line by line, the browser looks at the entire block and picks breaks that make the whole thing read better. That global pass costs a little more layout work, which is why you apply it selectively instead of spraying it on everything.
Why manual line breaks are not the answer
The classic fix is a hand-placed <br> inside the heading, or a gluing the last two words together. It looks perfect at exactly one viewport width. Resize the window, open it on a phone, or translate the page, and your carefully placed break lands in the wrong spot or creates a new orphan somewhere else.
The JavaScript route is no better: widow-fixing plugins re-run on every resize, add weight to every page, and can shift layout after paint. A native CSS declaration does the same job at the layout layer, responds to resizing for free, and degrades to ordinary wrapping where it is not supported.
balance: even lines for headings
text-wrap: balance distributes text so every line is roughly the same width. A three-line headline becomes three even lines instead of two full lines plus one stranded word. It is made for short blocks: headings, card titles, toast messages, empty-state copy.
h1, h2, h3, h4 {
text-wrap: balance;
}One gotcha to know: in Chromium-based browsers, balance only applies to blocks of six lines or fewer. Past that, the browser quietly falls back to normal wrapping. That is fine in practice, because balancing long text would look odd anyway, but it means balance belongs on headings, not on articles.
pretty: no more widows in body text
text-wrap: pretty is the gentler sibling. It keeps the lines roughly where greedy wrapping would put them, but intervenes at the end of the block so the last line never holds a single word. Newer versions also smooth out short last lines and stray gaps of whitespace mid-paragraph.
p, li {
text-wrap: pretty;
}Because pretty only reworks the last few lines instead of the whole block, it stays cheap enough for long paragraphs. That is the division of labor: balance rethinks short blocks completely, pretty tidies the endings of long ones.
The two-line base recipe
Put both together and every heading and paragraph on the site gets the treatment:
h1, h2, h3, h4 {
text-wrap: balance;
}
p, li {
text-wrap: pretty;
}That is the whole recipe. No classes to remember, no per-component decisions. New pages inherit it automatically, and old pages get better the next time they render.
One performance rule
Do not put balance on long body text. The global line-breaking pass is measurably more expensive than greedy wrapping, and on a thousand-word article it buys you nothing visually, since the middle lines were already full. Keep balance on headings and short blocks, pretty on paragraphs, and the cost stays negligible.
A polished hero to go with the polished headline
Balanced type looks best over a background with the same care put into it. uitweak's mesh gradient generator builds the layered gradient behind your hero visually. Export the CSS, drop your now-balanced headline on top, and the whole hero reads as designed instead of assembled.
Browser support
text-wrap: balance has broad support: Chrome 114+, Firefox 121+, Safari 17.5+. text-wrap: pretty is in Chrome 117+ and Safari 17.5+, with further improvements landing in Safari 26. Firefox support for pretty is inconsistent across sources, so treat it as progressive enhancement there.
- balance: Chrome/Edge 114+, Firefox 121+, Safari 17.5+
- pretty: Chrome/Edge 117+, Safari 17.5+ (enhanced in 26); Firefox varies, treat as enhancement
The fallback story is the selling point: a browser that does not know a value simply wraps text the old greedy way. Nothing breaks, nothing overlaps, nobody sees an error. You can ship the two-line recipe today with no @supports gate and no fallback CSS.
# Expansion draft: css-text-wrap-balance-pretty-guide
Where pretty Stops Helping
pretty fixes break decisions, not unbreakable content. A 60-character URL in a paragraph cannot be rebalanced into anything; it overflows or it does not, and no wrap value changes that. The same goes for long technical identifiers and German compound nouns in narrow columns. When I see a layout where pretty "is not working," the culprit is almost always one unbreakable token, not the property.
The fix is a companion declaration, not a different wrap value:
.article-body p {
text-wrap: pretty;
overflow-wrap: break-word;
}overflow-wrap: break-word gives the browser permission to split the long token; pretty then arranges everything else. They solve different halves of the problem. I also keep hyphens: auto with a lang attribute on the <html> element for prose-heavy pages, since hyphenation gives the balancer more legal break points to choose from. Without lang, hyphenation dictionaries never load and the declaration is dead weight.
balance Inside Narrow Containers
balance on a card title inside a 240px column can make things worse. The browser dutifully evens the lines, and you get four stubby lines where two uneven ones read better. Balancing assumes there is enough width for evenness to look intentional.
My rule: balance belongs on display type with room to breathe, not on every heading selector sitewide. The main guide's h1, h2, h3, h4 { text-wrap: balance } recipe is a fine default, but I scope card titles and sidebar headings back out:
h1, h2, h3 {
text-wrap: balance;
}
.card h3,
.sidebar h3 {
text-wrap: wrap; /* too narrow to balance well */
}An explicit wrap with a comment beats a mysterious absence of balance that the next developer "fixes" by adding it back.
How to Verify It Is Actually Applied
text-wrap fails silently in two situations, and both look identical: nothing changes. The first is lack of support (old browser, or pretty in a Firefox version that ignores it). The second is content the algorithm declines to touch, like the six-line cap on balance in Chromium or a single-line heading that has nothing to balance.
The fastest check is the resize test. Open DevTools, confirm text-wrap: balance shows in computed styles, then drag the viewport narrower. If line breaks redistribute as you drag, the property is live. If the breaks never move, either the block is past the line cap or the value is unsupported. For pretty, the tell is the last line: find a paragraph that ended on a single word before your change and check it after. One concrete before/after paragraph beats ten minutes of reading computed styles.
pretty and Justified Text
A common worry: does pretty fight text-align: justify? It does not. Justification stretches inter-word spacing to fill each line; pretty adjusts where the breaks fall, mostly at the end of the block. They compose without conflict, and the combination is genuinely useful: justified text with a ragged-aware last line avoids the classic justified paragraph that ends with one word stretched across the full measure.
One caution, though. Justified text plus hyphens: auto plus pretty is three layout opinions on one paragraph. Each is cheap alone, but stacked on very long articles they add measurable layout cost on low-end phones. For body copy I pick pretty plus either justification or hyphenation, not both, and I have never missed the third.
FAQ
What is the difference between pretty and balance?
balance redistributes the whole block so all lines are roughly equal, which suits headings and short text. pretty leaves the lines mostly alone and only fixes the ending, preventing orphan words and widows, which suits paragraphs. Use them together: balance on headings, pretty on body text.
Is it safe to use in production?
Yes. Both values are pure progressive enhancement. Unsupported browsers ignore the declaration and wrap text exactly as they did before, so there is no layout breakage to guard against. balance in particular is supported broadly enough to use without a second thought.
Does text-wrap: pretty work in Firefox?
Sources disagree on the exact Firefox status for pretty, with some listing support and others showing it ignored. The practical answer: it does not matter. Firefox users simply get normal wrapping, which is the same text they would have seen before you added the property. Ship it and let each browser do its best.
Related reading: Mesh gradients in pure CSS · text-decoration inset underlines
Try it: related UI elements
"This is the best tool I have used for CSS this year. The generators alone saved me hours."
Testimonial Card
Copy code →
Team Member Card
Copy code →
No projects yet
Get started by creating your first project. It only takes a minute and you can invite your team later.
Learn more about projects
Empty State
Copy code →
Ship landing pages twice as fast
Copy-paste Tailwind components with live previews. Just paste and ship.
Hero Section
Copy code →