asp.net.ph

Skip Navigation Links

text-align Attribute | textAlign Property

CSS Attributes Index   Text Attributes


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

Syntax


CSS { text-align: 'left' | 'right' | 'center' | 'justify' }
Script object.style.textAlign = sAlign ]

Possible Values


left Text is aligned to the left.
right Text is aligned to the right.
center Text is centered.
justified Text is justified.

The property is read/write with a default value of left; this attribute is not inherited.

Remarks

The justified possible value is available as of Microsoft® Internet Explorer® 4.0 or later.

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

Example

The following example demonstrates the effects of applying the different values possible for the CSS text-align attribute.

 Show me 

The following examples demonstrate use of inline event handlers to dynamically set the text alignment of an element. Both methods yield the same effect.

The sample below defines text-align style attributes in an embedded stylesheet, and invokes calls to the stylesheet in response to mouse events.

<style type="text/css">
<!--
   .center { text-align: center }
   .right { text-align: right }
   .justify { text-align: justify }
-->
</style>
...
<p id="msg" class="center"
   onmouseover="this.className='right'"
   onclick="this.className='justify'"
   onmouseout="this.className=''">
...
</p>

 Show me 

The sample below uses inline event handlers to dynamically set an object’s text alignment in response to mouse events.

<p id="msg" onmouseover="this.style.textAlign='center'"
   onclick="this.style.textAlign='right'"
   onmouseout="this.style.textAlign=''">
   ...
</p>

 Show me 

See Also

text-align, text-decoration, text-indent, text-justify, text-transform



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note