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, only their inline content.
/* 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; /* Block alignment values (Non-standard syntax) */ text-align: -moz-center; text-align: -webkit-center; /* Global values */ text-align: inherit; text-align: initial; text-align: unset;
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
|
Animation type | discrete |
Canonical order | order of appearance in the formal grammar of the values |
The text-align
property is specified as a single keyword chosen from the list of values below.
start
left
if direction is left-to-right and right
if direction is right-to-left.end
right
if direction is left-to-right and left
if direction is right-to-left.left
right
center
justify
justify-all
justify
, but also forces the last line to be justified.match-parent
inherit
, but the values start
and end
are calculated according to the parent's direction
and are replaced by the appropriate left
or right
value.start | end | left | right | center | justify | match-parent
<p class="example"> Integer elementum massa at nulla placerat varius. Suspendisse in libero risus, in interdum massa. Vestibulum ac leo vitae metus faucibus gravida ac in neque. Nullam est eros, suscipit sed dictum quis, accumsan a ligula. </p>
.example { text-align: left; border: solid; }
<p class="example"> Integer elementum massa at nulla placerat varius. Suspendisse in libero risus, in interdum massa. Vestibulum ac leo vitae metus faucibus gravida ac in neque. Nullam est eros, suscipit sed dictum quis, accumsan a ligula. </p>
.example { text-align: center; border: solid; }
<p class="example"> Integer elementum massa at nulla placerat varius. Suspendisse in libero risus, in interdum massa. Vestibulum ac leo vitae metus faucibus gravida ac in neque. Nullam est eros, suscipit sed dictum quis, accumsan a ligula. </p>
.example { text-align: justify; border: solid; }
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.:
.something { margin: auto; }
.something { margin: 0 auto; }
.something { margin-left: auto; margin-right: auto; }
Specification | Status | Comment |
---|---|---|
CSS Logical Properties and Values Level 1 The definition of 'text-align' in that specification. | Editor's Draft | No changes |
CSS Text Module 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 |
Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 1 | Yes | 1 | 3 | Yes | 1 |
Prefixed center , left , and right values for block alignment |
1 -webkit- | ? | 1 -moz- | No | ? |
1.3 -webkit- 1 -khtml- |
Flow-relative values start and end
|
1 | No | 1 | No | ? | 3.1 |
match-parent |
16 | ? | 40 | No | ? | No |
justify-all |
No | No | No | No | No | No |
Feature | Android webview | Chrome for Android | Edge mobile | Firefox for Android | IE mobile | Opera Android | iOS Safari |
---|---|---|---|---|---|---|---|
Basic support | Yes | Yes | Yes | 4 | Yes | Yes | ? |
Prefixed center , left , and right values for block alignment |
? | ? | ? | ? | ? | ? | ? |
Flow-relative values start and end
|
? | ? | ? | 4 | ? | ? | ? |
match-parent |
? | ? | ? | 40 | ? | ? | ? |
justify-all |
No | No | No | No | No | No | No |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/text-align