Skip to: content, navigation

by Tommy Olsson and Paul O’Brien

text-align (CSS property)

Browser support full matrix
IE5.5+ FF1+ Saf1.3+ Op9.2+
Buggy Full Full Full
Spec
Inherited Initial Version
Yes CSS1, 2

Example

This style rule makes text in h1 headings centered:

h1 {
  text-align: center;
}

Try it yourself!View all demos

Description

This property specifies how the inline content of a block is aligned, when the sum of the widths of the inline boxes is less than the width of the line box.

Value

The initial value is left if direction is ltr, and right if direction is rtl.

center
This value makes the text center justified.
justify
This value makes the text left and right justified. In this case, inline boxes may be stretched in addition to being repositioned. If white-space is pre or pre-line, the alignment is set to the initial value.
left
This value makes the text left justified.
right
This value makes the text right justified.

Compatibility

IE5.5Buggy
6.0Buggy
7.0Buggy
Firefox1.0Full
1.5Full
2.0Full
Safari1.3Full
2.0Full
3.0Full
Opera9.2Full
9.5Full

Internet Explorer for Windows versions up to and including 7 incorrectly align block-level boxes according to the text-align property, although it should only affect inline boxes. The value justify behaves like center for table caption boxes.

Internet Explorer for Windows versions up to and including 7 don’t support the value inherit.

User-contributed notes

ID:
#3
Date:
Tue, 22 Apr 2008 13:03:52 GMT
Contributed by:
AutisticCuckoo
Status:
This note has not yet been confirmed for accuracy and relevance.

@sebwin: Not according to the CSS2.1 specification <http://www.w3.org/TR/CSS21/text.html#propdef-text-align>.

It was in CSS2, but that option was removed in CSS2.1 since no user agent implemented it.

ID:
#2
Date:
Thu, 17 Apr 2008 09:54:54 GMT
Contributed by:
sebwin
Status:
This note has not yet been confirmed for accuracy and relevance.

For table cells specifying a string value is also permitted.
Compatibility information would be helpful here…

Add a note

To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.

Related Products

The Principles of Beautiful Web Design

Best Seller!

You don’t need to go to Art School to design great looking web sites!

Book Cover: The Principles of Beautiful Web Design

Download the FREE sample chapters