CSS text-align property

Examples

h1, h2, and h3 elements set text alignment:

h1 {text-align: center}
h2 {text-align: left}
h3 {text-align: right}



In the bottom of this page for more examples.

Attribute definitions and instructions

text-align attribute specifies the horizontal alignment of the text element.

Defaults: left if direction is ltr, and right if direction is rtl
inherit: yes
version: CSS1
JavaScript syntax: object .style.textAlign = "right"


Browser Support

Figures in the table represent the first browser to support the version number of the property.

Immediately following the digital -webkit-, -ms- or -moz- ago in support of the prefix attribute first browser version number.

属性
text-align 1.0 3.0 1.0 1.0 3.5

Property Value

value description
left The text-align to the left. Default: determined by the browser.
right The text-align to the right.
center The text-align to the middle.
justify Justify the text to achieve the effect.
inherit Provisions should inherit values ​​text-align property from the parent element.


Examples

More examples

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


related articles

CSS tutorial: CSS text