CSS/Properties/text-align

From W3C Wiki

text-align

The text-align property describes how inline-level content of a block container is aligned.

Description

Values left | right | center | justify | inherit
Initial value a nameless value that acts as 'left' if 'direction' is 'ltr', 'right' if 'direction' is 'rtl'
Applies to block containers
Inherited Yes


Values

  • left
    Aligns the inline text to the left.


  • right
    Aligns the inline text to the left.


  • center
    Centers the inline text.


  • justify
    Stretches spaces and words in inline boxes.


  • inherit
    Takes the same specified value as the property for the element's parent.


Example

Example A

[style.css]

 p {
   border: 1px solid black;
   text-align: center;
 }

[index.html]

  <body>
    <p>This is a paragraph</p>
  </body>

Example B

[style.css]

 p {
   width: 250px;
   border: 1px solid black;
   text-align: justify;
 }

[index.html]

  <body>
    <p>CSS is a Style Sheet Language for formatting the document content 
       (written in HTML or other markup language). You might be interested 
       by the CSS Working Group wiki too.</p>
  </body>

CSS Reference

The CSS specification defines the text-align property in 16.2 Alignment.