CSS Text Alignment

In this simple tip, I will show you how to align text on your webpage using the text align property with CSS.

Here are some examples:

h1 { text-align: center }
h2 { text-align: right }
h3 { text-align: justify }

Seems self-explanatory.

Text can be aligned to either of the following:

  • center
  • left
  • right
  • justify (lines have equal width)

It is important to remember that text align can only be used on block-level elements. That means any tags which add breaks around themselves (ie. <p>, <h1>, …).

Thanks

Roberto Cipriani

This post was written by: roberto-cipriani

This entry was posted on Monday, February 15th, 2010 at 5:28 am and is filed under Killer CSS Tips and Tricks. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply