How to Align Text in Css

May 04, 2012, by admin

In this undemanding 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 each of the following:

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

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