XML technologies / CSS / CSS Cookbook / Typography for the web / Displaying justified text

(Excerpt from “CSS Kochbuch” by Christopher Schmitt)

Problem

You want justified text, aligned with both the left and right margins, as shown in the following figure.

The paragraph is justified

Figure: The paragraph is justified.

Solution

Use the property text-align with the value justify:

P {
 width: 600px;
 text-align: justify;
}

Discussion

How well does justification work on the web? According to the specification for CSS 2.1 this depends on the algorithms used by browser developers. There is no standard, so justified text differs between browsers even when they support justification in principle. The following browsers provide good support for text-align: justify;: Internet Explorer 4+ for Windows, Internet Explorer 5 for Macintosh, Mozilla Firefox 1.5+, Safari and Opera 3+. Justified text is easy to read in these browsers. In others, it may look worse because large gaps can appear between words.

See also

The CSS 2.1 specification for the text-align property.

  

 

 

 

back to top