Back to blog
CSS5 min read

Stop Using Dodgy Line Breaks: Fix Your Typography with text-wrap

Chris from Pixelbricks•

For roughly three decades, building a good layout on the web involved a rather irritating dance with typography. You craft a punchy headline. You spend twenty minutes picking the right clamp formula so it scales nicely from mobile screens up to massive monitors. Then you check the live site, and one lone word is sitting on its own sad little line at the bottom.

An orphan. A typographic tragedy.

Historically, our industry reacted to this problem in the most unhinged ways imaginable. Some folks injected invisible non-breaking spaces into page headings using server scripts. Others reached for chunky JavaScript plugins to measure DOM elements and forcibly insert break tags. A few adventurous souls even attempted to prompt language models to rewrite their copy until the word count fit neatly into a rigid design box. Madness, absolute madness.

Thankfully, modern CSS stepped into the room and sorted it out properly with two values: text-wrap: balance and text-wrap: pretty. Let us look at what they actually do, how they behave, and why slapping them on every single paragraph on your site might not be the brightest idea.

The Problem with Greedy Line Wrapping

To understand why these properties exist, we have to remember how browsers normally wrap text. By default, browsers use what typographers call a greedy algorithm. The browser packs as many words into the first line as it can squeeze in. Once it runs out of space, it drops to the next line and repeats the process.

This greedy approach is blindingly fast. It renders huge walls of text in milliseconds without torching your user's battery life. But visually, it often produces headings where line one spans eighty characters and line two spans four characters. It looks lopsided. It makes design folk twitchy.

Advertisement

text-wrap: balance — The Heading Rescuer

When you set text-wrap: balance, you tell the browser to take a breath and distribute the characters across the available lines as evenly as possible.

Instead of stuffing line one to the brim and leaving one lonely word hanging on line two, the browser balances the total width of both lines. The result is a heading that looks intentional, balanced, and tidy.

h1, h2, h3, h4 {
  text-wrap: balance;
}

There is, however, an important catch. Balancing lines is computationally expensive. The browser has to test multiple possible breaking points to figure out which combination looks cleanest.

Because of that layout cost, browser engines put a hard cap on how many lines they will balance. Chromium browsers only apply balancing to blocks of six lines or fewer. Firefox caps it at ten lines or fewer. If you try to stick text-wrap: balance onto an entire twelve-paragraph article, the browser simply ignores the rule and falls back to standard greedy wrapping. That limit exists to protect your rendering performance, so leave it on short text like headings, card titles, and blockquotes.

text-wrap: pretty — The Paragraph Polisher

What about your body copy? Long blocks of text do not need balanced lines; in fact, balanced paragraphs would look bizarre and disrupt a reader's natural scanning rhythm. What you actually want in body copy is to prevent awkward orphan words dangling on the final line.

That is where text-wrap: pretty comes into play.

p {
  text-wrap: pretty;
}

Instead of trying to balance the entire paragraph, text-wrap: pretty uses an algorithm that specifically inspects the final four lines of a text block. If it notices that the final line contains only a single lonely word, it nudges a word from the preceding line down to join it. Two words on the last line look much better than one. It fixes the orphan without forcing the browser engine into layout gymnastics across the entire document.

Advertisement

Comparing text-wrap Values

To keep your stylesheet clean, here is how the two values compare:

Property ValuePrimary PurposeLine LimitIdeal Use Case
text-wrap: balanceDistributes characters evenly across lines6 lines (Chromium) / 10 lines (Firefox)Headings, hero titles, captions, quotes
text-wrap: prettyEliminates orphan words on final linesInspects the last 4 linesBody text, blog paragraphs, intro copy
text-wrap: wrapStandard greedy line wrappingNo limitDefault fallback for bulk text
text-wrap: nowrapPrevents text from breaking onto new linesN/ABadges, buttons, short tags

Browser Support and Safe Progressive Enhancement

According to Can I Use data, global support for text-wrap: balance sits comfortably above 92%. Modern versions of Chrome, Edge, Safari, and Firefox all support it. Support for text-wrap: pretty is slightly lower at around 87%, primarily driven by Chromium based browsers, with other engines catching up.

Here is the best part: you do not need polyfills, fallback hacks, or complex feature queries. Both properties are pure progressive enhancement. If an older browser does not recognise text-wrap: balance, it simply ignores the property and falls back to normal text wrapping. Nobody sees broken text; they just get the standard layout we lived with for twenty years.

Keeping the Rest of Your Layout Fast

Cleaning up your typographic layout takes two minutes with modern CSS. But neat typography does not help much if your pages still feel sluggish because the assets around that text are dragging things down.

A perfectly balanced headline sitting on top of a bloated 4MB PNG hero graphic will still test your visitor's patience. Before you marvel at your neatly balanced typography, run your heavy imagery through the free browser based tool at WEBP Converter. It converts heavy PNGs and JPGs into lightweight WebP files directly on your machine without uploading personal assets anywhere, making sure your quick layout matches your fast load times.

Frequently Asked Questions

Can I put text-wrap: balance on the universal selector?

Technically yes, but please do not. Running balancing calculations across every single element on a complex page wastes processing cycles. Restrict it to headings, pull quotes, and short captions where visual balance actually matters.

Does text-wrap: balance cause layout shifts?

Because the browser calculates line balance during its initial layout pass before painting the text on screen, it does not trigger cumulative layout shift when implemented properly in your regular CSS stylesheets.

How does Tailwind handle this?

Modern releases of Tailwind CSS include both utility classes out of the box. You can use the class text-balance for headings and text-pretty for body copy.

The Bottom Line

You no longer need clunky JavaScript scripts, brittle manual break tags, or mysterious invisible characters to make your headings look human. Drop text-wrap: balance on your headings, add text-wrap: pretty to your body copy, and let the browser engine do what it was built to do.

CF

Chris from Pixelbricks

Web designer at Pixelbricks Design in London. Built WEBP Converter to help designers and developers optimise their images for free, right in the browser — no uploads, no limits, no cost.

Visit Pixelbricks Design →
Was this helpful?

Ready to optimise your images?

Try our free WebP converter and see the difference for yourself. Unlimited conversions, no registration required.

Start converting →

We use cookies

We use cookies to improve your experience and analyze how our website is used. Your images are always processed locally and never stored or tracked. You can learn more in our Cookie Policy.