text-align property CSS Reference



Definition and Usage

The text-align CSS property describes how inline content like text is aligned in its parent block element. text-align does not control the alignment of block elements itself, only their inline content.

  • Initial start, or a nameless value that acts as left if direction is ltr, right if direction is rtl if start is not supported by the browser.
  • Applies to block containers
  • Inherited yes
  • Media visual
  • Computed Value as specified, except for the match-parent value which is calculated against its parent's direction value and results in a computed value of either left or right
  • Animatable no
  • Canonical order order of appearance in the formal grammar of the values

Syntax

Formal syntax: [ start | end | left | right | center ] || <string> ] | justify | match-parent | start end
text-align: left
text-align: right
text-align: center
text-align: justify
text-align: start
text-align: end
text-align: match-parent
text-align: start end
text-align: "."
text-align: start "."
text-align: "." end
text-align: inherit

Values

start
The same as left if direction is left-to-right and right if direction is right-to-left.
end
The same as right if direction is left-to-right and left if direction is right-to-left.
left
The inline contents are aligned to the left edge of the line box.
right
The inline contents are aligned to the right edge of the line box.
center
The inline contents are centered within the line box.
<string>
The first occurrence of the one-char string is the element used for alignment. the keyword that follows or precedes it indicates how it is aligned. This allows to align numeric values on the decimal point, for instance.
justify
The text is justified. Text should line up their left and right edges to the left and right content edges of the paragraph.
match-parent
Similar to inherit with the difference that the value start and end are calculated according the parent's direction and are replaced by the adequate left or right value.

Examples

div { text-align: center; border:solid; }

p { background:gold; width:22em; }

some more inline content...
div { text-align: center; border:solid; }

p { background:gold; width:22em; margin: 1em auto; }

some more inline content...
div { text-align:-moz-center; text-align:-webkit-center; border:solid; }

p { background:gold; width:22em; }

some more inline content...

Compatibility

Desktop browsers

FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support (left, right, center and justify)1.01.0 (1.7 or earlier)3.03.51.0 (85)
Block alignment values Non-standard1.0-webkit1.0 (1.7 or earlier)-mozNot supportedNot supported1.0 (85)-khtml
1.3 (312)-webkit
start1.01.0 (1.7 or earlier)Not supported(Yes)3.1 (525)
end1.03.6 (1.9.2)Not supportedNot supported3.1 (525)
match-parent16Not supportedNot supportedNot supportedNot supported
<string> valueNot supportedNot supportedNot supportedNot supportedNot supported

Mobile browsers

FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic supportNANANANANANA
Block alignment values Non-standardNANANANANANA
startNANANANANANA
endNANANANANANA
match-parentNANANANANANA
<string> valueNANANANANANA

Relative articles