DEV Community

Martin Milani
Martin Milani

Posted on

2

Exploring text-wrap: balance and text-wrap: pretty in CSS

In the world of CSS, the handling of text within containers often requires careful consideration to maintain readability and aesthetics. Two lesser-known CSS properties, text-wrap: balance and text-wrap: pretty, offer intriguing solutions for text layout. Let's dive into these properties and understand their capabilities.

text-wrap: balance

Mainly use to balancing headlines text-wrap: balance attempts to distribute the text evenly across lines, reducing the unevenness often seen in standard text layouts.

Consider the following example:

Wrap-balance

.balanced {
  text-wrap: balance;
}
Enter fullscreen mode Exit fullscreen mode

text-wrap: pretty

On the other hand, text-wrap: pretty will try to intelligently break the text in block elements in such a way that there wouldn’t be a single/orphan word on the last line.

Consider the following example:

wrap-pretty

p {
  text-wrap: pretty;
}
Enter fullscreen mode Exit fullscreen mode

As for the browser support, the text-wrap: pretty is estimated to be landed in Chrome 117 across desktop and Android browsers.

(All images by developer.chrome.com)

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay