Not one of our 662 headings balances its lines, and the fix is two Tailwind classes and no reflow
text-wrap: balance and text-wrap: pretty are the cheapest typographic upgrade available to a web page, and the reason they do not get applied is that nobody can tell you what they would be worth on your particular site.
text-wrap: balance and text-wrap: pretty are the cheapest typographic upgrade available to a web page, and the reason they do not get applied is that nobody can tell you what they would be worth on your particular site. So I measured it on Nakodo, which has 76 public pages, 662 headings and about 3,200 blocks of body text.
What the site does today
Every heading on every public page computes to the default:
text-wrap on 662 headings: wrap (662 of 662)
hyphens on 662 headings: manual (662 of 662)
non-breaking spaces in the HTML of all 76 pages: 0
soft hyphens: 0
No balancing, no automatic hyphenation, and no manual widow control either, which is the honest state of most sites. The stylesheet does contain the utilities, because Tailwind only emits what is used:
.text-balance{text-wrap:balance}.text-pretty{text-wrap:pretty}
Four uses across 582 source files. Two of them are 13px tour notes on the home page, and two are the description slots inside alert.tsx and alert-dialog.tsx, which arrived with the component library and are only reachable behind the login. The public typography has none.
Measuring a widow
Line breaks are not in the DOM, so the only way to count rendered lines is to ask the layout where each word ended up. A Range per word, grouped by rounded top, gives lines with their word counts and widths:
const r = document.createRange();
r.setStart(node, m.index);
r.setEnd(node, m.index + m[0].length);
const rect = r.getBoundingClientRect();
items.push({ top: Math.round(rect.top), word: m[0], left: rect.left, right: rect.right });
// group items by top, within 4px, and each group is a rendered line
For the 662 headings (76 h1, 576 h2, 10 h3):
| Rendered lines | Headings |
|---|---|
| 1 | 552 |
| 2 | 97 |
| 3 | 13 |
110 headings wrap at all, and 20 of those end on a single word. That is the classic defect, and here it is in full, with the last word and how wide that last line is as a share of the heading's widest line:
/guides/micro-influencers-on-youtube "them" 18%
/guides/instagram-and-tiktok-... "TikTok" 27%
/tools/engagement-rate-calculator "calculator" 38%
/youtubers/tech "sponsor" 26%
/tiktokers/books "brand" 21%
/for/saas "doesn't" 15%
/alternatives/hypeauditor "them" 18%
The four calculator pages are the clearest case, because their titles are near-identical and all four break the same way: "YouTube engagement rate calculator" puts the word "calculator" alone on line two, 229px of it under a 599px line.
What balance does, measured
Inject one declaration and measure the same headings again:
const st = document.createElement("style");
st.textContent = "h1,h2,h3{text-wrap:balance}";
document.head.appendChild(st);
| Before | After | |
|---|---|---|
| Heading lines, total | 785 | 785 |
| Median last line as a share of the widest line | 41.5% | 100% |
| Headings whose line count changed | 0 |
Nothing moves vertically. Not one of the 110 multi-line headings gains or loses a line, so no layout shifts, no cards get taller, no grid rows change. What changes is the distribution of words between lines that already existed, and a median last-line share of 100% means that after balancing, the last line is typically the widest one, which is what an even block looks like. The 20 widows all improve: 18% to 85%, 14% to 83%, 38% to 67%, 25% to 100%.
That is the entire cost and benefit of text-balance on this site. One class on two components, no reflow, and the twenty ugliest headings stop being ugly.
What pretty does, measured
The same test on body text, with one page excluded for a reason I will come back to. 3,163 blocks on 75 pages (1,726 p, 1,125 li, 312 dd), of which 2,838 take more than one line:
| Last line as a share of the widest line | Before | With text-wrap: pretty
|
|---|---|---|
| 10% or less | 278 | 150 |
| 15% or less | 462 | 337 |
| 20% or less | 616 | 523 |
| 25% or less | 759 | 717 |
365 blocks improved, zero got worse, zero changed line count, and the total height of all 75 pages was identical to the pixel before and after. The worst offenders are the ones you would wince at in print: a 210-character paragraph on product seeding whose third line is 2% of the width of the other two, and a list item on the privacy notice doing the same thing.
pretty fixes a bit over half of the worst cases rather than all of them, which is the honest shape of this feature: it can only pull a word down from the line above when that line has a word it can spare. A 15-character word at the end of a tight measure stays where it is.
The page I had to throw out
The home page reported a 150-character paragraph as 127 rendered lines. That is not a layout bug, it is my measurement meeting the hero animation: 45 leaves on a requestAnimationFrame loop and a tour of example cards, so the client rects I was collecting word by word were taken at different moments of different frames, and every word landed on its own "line".
Two lessons. Range-rect measurement assumes a still page, so freeze or exclude anything animated before you believe a line count. And the reason it only happened once is that this site has exactly one page with animation on it, which I know from an earlier sweep where 75 of 76 pages returned an empty document.getAnimations().
What I am changing
text-balance on the content heading components and text-pretty on the body text, both measured above as free: no height change on any page, no line-count change anywhere, 20 heading widows and 365 ragged paragraph tails improved. The remaining 150 tiny last lines are a copy problem rather than a CSS one, and the places they show up are mostly list items where the sentence could simply be shorter.
If you want to see the before state, it is still live while I ship this: the four calculators all break their titles the same way, the niche pages end their headings on the word "brand", and the guides are where the paragraph tails are.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.