Export (0) Print
Expand All
top
Expand Minimize

text-align

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 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) Ee371304.xtlink_newWindow(en-us,Expression.40).png.

Applies to

address, 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

See also

Send feedback about this topic to Microsoft. © 2011 Microsoft Corporation. All rights reserved.

Community Additions

ADD
Show:
© 2014 Microsoft