text-wrap: balance and pretty for better headings and paragraphs
A long heading that wraps with a single word on its second line, or a paragraph that ends with one lonely word, looks careless, and designers used to fix it with in the content or a script that measures lines. Two values of text-wrap let the browser do it: balance distributes the words of short text evenly across its lines, pretty avoids a too short last line in longer text.
Problem: A theme’s post titles and card headings often break with one word on the last line, and the last lines of paragraphs end with single words. Editors add non-breaking spaces by hand, which breaks again on other screen widths.
Solution: Set text-wrap: balance on headings, captions and short card titles, and text-wrap: pretty on body paragraphs, in the theme’s theme.json or stylesheet. Both are progressive enhancements: browsers without support wrap as before.
balance for headings
h1, h2, h3,
.wp-block-post-title,
.wp-block-heading,
figcaption,
.ha-card__title {
text-wrap: balance;
}
The browser tries line breaks so that all lines are about the same length. A heading of two lines gets two similar lines instead of a full first line and one word below. Balancing is limited to short text (Chrome balances up to six lines, Firefox up to ten) because it is expensive; on longer text the value has no effect.
pretty for paragraphs
.entry-content p,
.wp-block-post-content p {
text-wrap: pretty;
}
pretty keeps normal wrapping but looks at the last lines of a paragraph and avoids a very short last line (an orphan), moving a word down if needed. Unlike balance, it does not try to equalize all lines, so paragraphs keep their natural shape. It costs a little more layout time, which is irrelevant for normal articles and not worth applying to huge texts or tables.
In theme.json
{
"version": 3,
"styles": {
"blocks": {
"core/heading": {
"css": "text-wrap: balance;"
},
"core/post-title": {
"css": "text-wrap: balance;"
},
"core/paragraph": {
"css": "text-wrap: pretty;"
}
}
}
}
The css property of a block in theme.json (WordPress 6.2+) adds custom CSS scoped to that block, for declarations that have no dedicated theme.json setting.
Things to keep in mind
- Balanced headings can be narrower than their box. A heading with a background color or a border at the bottom shows that; use
width: fit-contentif the box should follow the text. - Do not combine with
that editors added earlier: they still force words together and fight the balancing. Search the content for them once if the site used that workaround. text-wrapis a shorthand fortext-wrap-modeandtext-wrap-style;text-wrap: nowrapreplaceswhite-space: nowrapin new code.
NOTE: text-wrap: balance works in Chrome 114, Firefox 121 and Safari 17.5. pretty works in Chrome 117 and Safari 26 (September 2025); check the current Firefox support before relying on it. Where it is missing, paragraphs simply wrap as before. Fluid font sizes for the same headings: theme.json and fluid typography.