Style textAlign Property
The Style object
Definition and Usage
The textAlign property sets or returns the horizontal alignment of text in a block-level element.
Syntax
Set the textAlign property:
Object.style.textAlign="left|right|center|justify|inherit"
Return the textAlign property:
Object.style.textAlign
| Value | Description |
|---|---|
| left | Default. Aligns the text to the left. |
| right | Aligns the text to the right. |
| center | Aligns the text to the center. |
| justify | Aligns the text according to the textJustify property. |
| inherit | The value of the textAlign property is inherited from the parent element. |
Browser support





All major browsers support the textAlign property.
**Note:** IE7 and earlier versions do not support the "inherit" value. IE8 supports "inherit" only if a !DOCTYPE is specified. IE9 supports "inherit".
Example
Example
Center-align the text in a p element:
This is some text.
Try it »
The Style object