Software, your way.
burger menu icon
WillMaster

WillMaster > LibraryWeb Content Preparation

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Automatic Wrap Balancing for Headlines

Long headlines tend to wrap at different points depending on the width available for it. There are many different screen sizes.

On some devices, the headline might have a one-word line at the end. On others, the text wrapping may be aesthetically pleasing with nearly equal line lengths.

I'll publish a few headline examples here. Because I don't know how wide your screen is, I don't know where the line breaks will be. The intent is to demonstrate at least one headline ending with a short word.

One Two Three Four Five

One Two Three Four Five Six

One Two Three Four Five Six Seven

One Two Three Four Five Six Seven Eight

One Two Three Four Five Six Seven Eight Nine

Now, let's balance those line lengths with the CSS text-wrap:balance; declaration. That particular CSS declaration will try to balance the lines by counting the characters in each line and breaking the line between words for the most balanced result.

One Two Three Four Five

One Two Three Four Five Six

One Two Three Four Five Six Seven

One Two Three Four Five Six Seven Eight

One Two Three Four Five Six Seven Eight Nine

The CSS text-wrap property is available with most of the latest browsers. If you are using an older browser, this CSS might have no effect.

Doing the line length calculations is computationally expensive. In other words, it requires the browser to make a lot of calculations. text-wrap:balance; is supported for blocks of text spanning a limited number of lines. Firefox limits it to 10 lines. Other browsers are likely to have their own limits. Therefore, use it with headlines but not with regular text.

If you put text-wrap:balance; into the sitewide stylesheet for each of the HTML headline tags, any headlines in your entire site should suddenly become more balanced. That is, unless you tend to manually insert linebreaks into headlines.

Test text-wrap:balance; and see how well it does or does not balance headlines for you.

(This content first appeared in Possibilities newsletter.)

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2025 Will Bontrager Software LLC