The text-align
CSS property sets the horizontal alignment of the inline-level content inside a block element or table-cell box. This means it works like vertical-align
but in the horizontal direction.
The text-align
CSS property sets the horizontal alignment of the inline-level content inside a block element or table-cell box. This means it works like vertical-align
but in the horizontal direction.
/* Keyword values */ text-align: start; text-align: end; text-align: left; text-align: right; text-align: center; text-align: justify; text-align: justify-all; text-align: match-parent; /* Character-based alignment in a table column */ text-align: "."; text-align: "." center; /* Block alignment values (Non-standard syntax) */ text-align: -moz-center; text-align: -webkit-center; /* Global values */ text-align: inherit; text-align: initial; text-align: revert; text-align: revert-layer; text-align: unset;
The text-align
property is specified in one of the following ways:
start
, end
, left
, right
, center
, justify
, justify-all
, or match-parent
.<string>
value only, in which case the other value defaults to right
.<string>
value.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 inline contents are justified. Text should be spaced to line up its left and right edges to the left and right edges of the line box, except for the last line.
justify-all
Experimental
Same as justify
, but also forces the last line to be justified.
match-parent
Similar to 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.
<string>
Experimental
When applied to a table cell, specifies the alignment character around which the cell's contents will align.
The inconsistent spacing between words created by justified text can be problematic for people with cognitive concerns such as Dyslexia.
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 |
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 |
<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: start; 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; }
Specification |
---|
CSS Logical Properties and Values Level 1 # text-align |
CSS Text Module Level 3 # text-align-property |
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
text-align |
1 | 12 | 1 | 3 | 3.5 | 1 | ≤37 | 18 | 4 | 10.1 | 1 | 1.0 |
block_alignment_values |
1 | 79 | 1 | No | 15 | 1.31preview | 37 | 18 | 4 | 14 | 11 | 1.0 |
flow_relative_values_start_and_end |
1 | 79 | 1 | No | 15 | 3.1 | 37 | 18 | 4 | 14 | 2 | 1.0 |
match-parent |
16 | 79 | 40 | No | 15 | 15.4 | 37 | 18 | 40 | 14 | 15.4 | 1.0 |
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/text-align