Sets whether the text in the object is left-aligned, right-aligned, centered, or justified.
Syntax
{ text-align: sAlign }
Possible values
sAlign
String that specifies or receives one of the following values:
left | Default. Text is aligned to the left. |
center | Text is centered. |
justify | Text is justified. |
right | Text is aligned to the right. |
The property has a default value of left. It is inherited.
Remarks
The property applies to block elements. The property is inherited by all block-level objects inside a DIV object.
Examples
The following example uses the text-align property to align text within the object. This example uses the P element as a selector and two classes to call an embedded style sheet that aligns the text according to the respective rule:
![]() | |
---|---|
<style> p {text-align:center} .align1 {text-align:right} .align2 {text-align:justify} </style> </head> <body> <p onclick= "this.className='align1'" ondblclick="this.className='align2'"> . . . </p> |
This example uses inline scripting to change the alignment of the text when an onmouseover event occurs:
![]() | |
---|---|
<p style="font-size:14" onmouseover="this.style.textAlign='center'"> . . . </p> |
Standards information
This property is defined in Cascading Style Sheets (CSS), Level 1 (CSS1).
Applies to
BLOCKQUOTE, BODY, CENTER, DD, DIV, DL, DT, FIELDSET, FORM, HN, HR, INPUT TYPE=PASSWORD, INPUT TYPE=TEXT, LI, OL, P, TABLE, TD, TH, TR, UL, XMP