Summary

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 value 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

/* Keyword values */
text-align: left;
text-align: right;
text-align: center;
text-align: justify;
text-align: justify-all;
text-align: start;
text-align: end;
text-align: match-parent;

/* Global values */
text-align: inherit;
text-align: initial;
text-align: unset;

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.
justify
The text is justified. Text should line up their left and right edges to the left and right content edges of the paragraph.
justify-all
Same as justify, but also forces the last line to be justified.
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.

Formal syntax

start | end | left | right | center | justify | match-parent | start end

Examples

View Live Examples

Live 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...

Notes

The standard-compatible way to center a block itself without centering its inline content is setting the left and right margin to auto, e.g.:
margin:auto; or margin:0 auto; or  margin-left:auto; margin-right:auto;

Specifications

Specification Status Comment
CSS Text Level 3
The definition of 'text-align' in that specification.
Working Draft Added the start, end, and match-parent values. Changed the unnamed initial value to start (which it was).
CSS Level 2 (Revision 1)
The definition of 'text-align' in that specification.
Recommendation No changes
CSS Level 1
The definition of 'text-align' in that specification.
Recommendation Initial definition.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (left, right, center and justify) 1.0 1.0 (1.7 or earlier) 3.0 3.5 1.0 (85)
Block alignment values 1.0-webkit 1.0 (1.7 or earlier)-moz [1] Not supported Not supported 1.0 (85)-khtml
1.3 (312)-webkit [1]
start 1.0 1.0 (1.7 or earlier) Not supported (Yes) 3.1 (525)
end 1.0 3.6 (1.9.2) Not supported Not supported 3.1 (525)
match-parent 16 40 (40) Not supported Not supported Not supported
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? ? ? ? ? ?
Block alignment values ? ? ? ? ? ?
start ? ? ? ? ? ?
end ? ? ? ? ? ?
match-parent ? ? 40.0 (40) ? ? ?

[1] Both WebKit and Gecko supports a prefixed version of left, center, and right, that applies not only to inline content but also to block elements. This is used to implement the legacy align attributes on some table-related element. Do not use these on production Web sites.

See also

Document Tags and Contributors

Last updated by: Sebastianz,