Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

CSS text-align property

CSS text-align property

Example

Set the text alignment of h1, h2, and h3 elements:

h1

{

text-align:

center

}

h2

{

text-align:

left

}

h3

{

text-align:

right

}

Try it »

There are more examples at the bottom of this page.


Property definition and usage

The text-align property specifies the horizontal alignment of an element's text.

Default value: If the direction property is ltr, the default value is left; if the direction property is rtl, the default value is right.
Inherited: yes
Version: CSS1
JavaScript syntax: object.style.textAlign="right"

Browser support

The numbers in the table indicate the first browser version that supports this property.

A number immediately before -webkit-, -ms-, or -moz- indicates the first browser version that supports that prefixed property.

property
text-align 1.0 3.0 1.0 1.0 3.5

Attribute values

Value Description
left Align the text to the left. Default value: determined by the browser.
right Aligns the text to the right.
center Aligns the text to the center.
justify Justify the text (align it to both edges).
inherit Specifies that the text-align property should be inherited from the parent element.

More examples

More advanced text alignment examples
This example demonstrates a more advanced text alignment.


Related Articles

CSS Tutorial: CSS Text