Style textAlign property

Definition and Usage

textAlign Sets or returns the horizontal alignment of the text in block-level elements.

See also:

CSS Tutorial:Texto CSS

CSS Reference Manual:text-align property

Example

Example 1

The text in the <p> element is centered:

document.getElementById("myP").style.textAlign = "center";

Try it yourself

Example 2

Returns the text alignment of the <p> element:

alert(document.getElementById("myP").style.textAlign);

Try it yourself

Syntax

Return textAlign property:

object.style.textAlign

Set textAlign property:

object.style.textAlign = "left|right|center|justify|initial|inherit"

Attribute value

Value Description
left Aligns the text to the left. Default.
right Aligns the text to the right.
center Centers the text.
justify The text is adjusted (for left and right alignment).
initial Sets this property to its default value. See initial.
inherit Inherits this property from its parent element. See inherit.

Technical details

Default value: left
Return value: String, representing the horizontal alignment of the text within the element.
Versão do CSS: CSS1

Suporte do navegador

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Suporte Suporte Suporte Suporte Suporte