CSS text-align Property
Example
Set the text alignment for different <div> elements:
div.a {
text-align: center;
}
div.b {
text-align: left;
}
div.c {
text-align: right;
}
div.c {
text-align:
justify;
}
Try it Yourself »
More "Try it Yourself" examples below.
Definition and Usage
The text-align
property specifies the horizontal alignment of text in an element.
Default value: | left if direction is ltr, and right if direction is rtl |
---|---|
Inherited: | yes |
Animatable: | no. Read about animatable |
Version: | CSS1 |
JavaScript syntax: | object.style.textAlign="right" Try it |
Browser Support
The numbers in the table specify the first browser version that fully supports the property.
Property | |||||
---|---|---|---|---|---|
text-align | 1.0 | 3.0 | 1.0 | 1.0 | 3.5 |
CSS Syntax
text-align: left|right|center|justify|initial|inherit;
Property Values
Value | Description | Demo |
---|---|---|
left | Aligns the text to the left | Demo ❯ |
right | Aligns the text to the right | Demo ❯ |
center | Centers the text | Demo ❯ |
justify | Stretches the lines so that each line has equal width (like in newspapers and magazines) | Demo ❯ |
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
More Examples
Example
Another text-align example:
h1 {
text-align: center;
}
p.date {
text-align: right;
}
p.main {
text-align: justify;
}
Try it Yourself »
Related Pages
CSS tutorial: CSS Text Alignment
HTML DOM reference: textAlign property