2 min read

How to Display Slogans More Effectively - A Quick Guide to Understanding the text-wrap: balance CSS Property

Table of Contents

Introduction

The text-wrap: balance property balances the number of characters per line, even with sufficient width.

This image effectively demonstrates this typographic feature.

p

This text layout is especially effective for displaying centered content, such as slogans and other elements on website homepages.

For example, the following GIF clearly demonstrates the significant improvement brought by the balance effect.

p

In the past, achieving such effects often required the use of the <wbr> tag.


Another Scenario

While the text-wrap property is meant to control text layout, it can actually be applied to any inline element.

We can now use text-wrap: balance to achieve layout effects that were previously difficult to implement.

For example, when showing user avatars for a β€˜like’ feature, the layout might have looked like this: the first line could have many items, and the second line just a few, resulting in an uneven and unattractive layout, as shown below.

p

If we use the text-wrap: balance declaration, each line will have as many avatars as possible, providing a much better user experience, as seen in the image below.

p


Browser Compatibility and Polyfill

The text-wrap: balance property is part of the CSS Text Level 4 spec, which is fairly recent. Currently, it is supported only by Chrome and browsers using its engine.

p

Although compatibility is generally limited, Adobe offers a well-established polyfill solution.

You can find the project at git

The project currently has 1.3K stars and is compatible with Internet Explorer.