Click to return to the DHTML, HTML     
text Property     text-autospace Attribute ...     DHTML Properties    
Web Workshop  |  DHTML, HTML & CSS

text-align Attribute | textAlign Property


Sets or retrieves whether the text in the object is left-aligned, right-aligned, centered, or justified.

Syntax

HTML{ text-align: sAlign }
Scriptingobject.style.textAlign [ = sAlign ]

Possible Values

sAlign String that specifies one of the following values:
leftText is aligned to the left.
right Text is aligned to the right.
centerText is centered.
justifyText is justified.

The property is read/write with a default value of left; the cascading style sheets (CSS) attribute is inherited.

Expressions can be used in place of the preceding value(s), as of Microsoft® Internet Explorer 5. For more information, see Dynamic Properties.

Remarks

The justify possible value is available as of Internet Explorer 4.0.

Because this property is inherited, all block-level objects inside a DIV object having textAlign=center are centered.

Example

This examples uses the text-align attribute and the textAlign property to align text within the object.

This example uses P as a selector and two classes to call an embedded style sheet that aligns the text according to the respective rule.

Sample Code

<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 feature requires Internet Explorer 4.0 or later. Click the icon below to install the latest version. Then reload this page to view the sample.
Microsoft Internet Explorer

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>

This feature requires Internet Explorer 4.0 or later. Click the icon below to install the latest version. Then reload this page to view the sample.
Microsoft Internet Explorer

Applies To

[ Object Name ]
PlatformVersion
Win16:
Win32:
Mac:
Unix:
WinCE:
BLOCKQUOTE, BODY, CENTER, currentStyle, DD, DIR, DIV, DL, DT, FIELDSET, FORM, Hn, HR, INPUT type=password, INPUT type=text, LI, LISTING, MARQUEE, MENU, OL, P, PLAINTEXT, PRE, runtimeStyle, style, TABLE, TD, TEXTAREA, TH, TR, UL, XMP


Back to topBack to top

Did you find this topic useful? Suggestions for other topics? Write us!

© 1999 Microsoft Corporation. All rights reserved. Terms of use.