Style textAlign Property
Example
Center-align the text in a <p> element:
document.getElementById("myP").style.textAlign = "center";
Try it Yourself »
Definition and Usage
The textAlign property sets or returns the horizontal alignment of text in a block level element.
Browser Support
Property | |||||
---|---|---|---|---|---|
textAlign | Yes | Yes | Yes | Yes | Yes |
Syntax
Return the textAlign property:
object.style.textAlign
Set the textAlign property:
object.style.textAlign = "left|right|center|justify|initial|inherit"
Property Values
Value | Description |
---|---|
left | Aligns the text to the left. This is default |
right | Aligns the text to the right |
center | Centers the text |
justify | The text is justified |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
Technical Details
Default Value: | left |
---|---|
Return Value: | A String, representing the horizontal alignment of text within the element |
CSS Version | CSS1 |
More Examples
Example
Return the text alignment of a <p> element:
alert(document.getElementById("myP").style.textAlign);
Try it Yourself »
Related Pages
CSS tutorial: CSS Text
CSS reference: text-align property
❮ Style Object