Style textAlign Property
Example
Center-align the text in an element:
document.getElementById("demo").style.textAlign = "center";
Try it Yourself »
Description
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 an element:
alert(document.getElementById("demo").style.textAlign);
Try it Yourself »
Related Pages
CSS tutorial: CSS Text
CSS reference: text-align property
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.