Aligning Text

You can set up certain (X)HTML elements to always be aligned to the right, left, center, or justified, as desired.

To align text:


Type text-align:.


Type left to align the text to the left.

Or type right to align the text to the right.

Figure 10.33. Don't forget the hyphen in text-align.

Or type center to center the text in the middle of the screen.

Or type justify to align the text on both the right and left.


  • If you choose to justify the text, be aware that the word spacing and letter spacing may be adversely affected. For more information, consult Controlling Spacing on page 162.

  • Note that the text-align property can only be applied to block-level elements. If you want to align inline content, you must place that inline content within a block-level element like p or div to which you've applied the text-align property. Also see pages 174175.

    Figure 10.34. The table of contents and headers are centered while the paragraph text is justified.

  • The text-align property is inherited. Its default value is supposed to depend on the document's language and writing system, but in most cases it's indiscriminately set to left.

HTML, XHTML, & CSS(c) Visual QuickStart Guide
HTML, XHTML, and CSS, Sixth Edition
ISBN: 0321430840
EAN: 2147483647
Year: 2004
Pages: 340

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: