Additional CSS Resources

CSS Text Alignment

February 15, 2010

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