CSS/Properties/text-align

From W3C Wiki
< CSS‎ | Properties
Revision as of 18:00, 16 June 2011 by Hiroki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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>

Csslist2 text-align.png

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>

Csslist2 text-align2.png

CSS Reference

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