by Larisa Thomason,
Senior Web Analyst,
Web designers who want their page layout to closely resemble print layout often "justify" their text so that each line of text will be equal length. Use justify carefully though, or you could have some unexpected browser display problems.
The problems stem from several sources. You already know this, but we'll say it again: browsers may not display the same page elements consistently. For instance, a common font like Arial may display in a completely different typeface in Netscape than Explorer if you leave out the size attribute.
Similarly, the justified text that looks great in one browser may look quite different when viewed in another.
For instance, compare the word spacing differences between Netscape and Explorer for this justified quotation:
In this example, Netscape's rendering looks better than Explorer's, but the webmaster of DeepSouthSports.com alerted us to a Netscape quirk that could give you fits if you aren't aware of it.
Mystery Words In Netscape
It's the phenomenon of mystery words that repeat onscreen even though the actual HTML code contains the word only once. This problem is relatively rare, but it can be almost impossible to solve. Suppose you have this quote on your Web page:
See the extra word? When a short paragraph is justified, Netscape will sometimes repeat the ending word of the first line and make it the first word of the second line.
Frustrated webmasters will immediately note that the quote looks just fine in Explorer and Opera and start combing through their source code, looking for that extra "times." But they won't find it. The only way to solve the problem is to remove the justify attribute.
Know When To Justify
As a general rule, never justify paragraphs that take less than two complete lines to display. Otherwise, you could get really unusual word spacing and/or duplicate words like we showed in our examples.
If you're including the align attribute inside each of your paragraph tags, it's pretty easy to judge when justify isn't needed. Trouble can occur though if you use style sheets to set a style attribute that justifies the text of every paragraph. Cascading style sheets simplify coding because you just declare formatting information once instead of with each individual tag.
If you use style sheets to justify paragraphs, be sure to declare a separate class for short paragraphs. Thus, your style specification might look something like this:
So in your code, the long paragraphs would automatically be justified when you use the paragraph tag, but you'd have to add a class attribute to short ones so they would be left-justified:
The mystery words and strange line spacing won't show up every time or in every browser. That's why it's critical to test your pages on as many browsers and platforms as you can. But that can be time-consuming - not to mention expensive!
Consider letting Browser Photo do the work for you. It will show you actual screen shots of your Web page in 16 different browser versions and operating system combinations. It's a quick and cost-effective way to test your pages.