Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML DOM Style textAlign Property

Style textAlign Property

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

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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:

Runoob Tutorial(runoob.com)

This is some text.


Try it »


Style Object Reference The Style object