X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

Style textAlign Property

Style Object Reference Style Object

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

Internet Explorer Firefox Opera Google Chrome Safari

The textAlign property is supported in all major browsers.


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 Reference Style Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook