CSS Reference ยท Typography
The text-align property
Reference for the CSS text-align property: start, end, center, justify and match-parent, why it aligns inline content only, with live examples.
The text-align property sets how the inline content of a block (text, inline images, inline-block elements) is aligned horizontally inside each line. It is set on the block container, not on the text, and it is inherited, so setting it on a parent aligns all the paragraphs inside.
It does not move block-level boxes. To center a <div> itself, use auto margins, flexbox or grid.
.card { text-align: center; }
Try it
The red inline-block circles are centered. The blue block box is not, because it is a block with a fixed width and text-align only affects inline content.
Syntax
text-align: start | end | left | right | center | justify | justify-all | match-parent;
- Initial value:
start - Applies to: block containers
- Inherited: yes
- Animatable: no
- Computed value: as specified, except that
match-parentresolves toleftorrightfrom the parent's direction
Values
| Value | Description |
|---|---|
start |
Aligns to the start edge of the line. This is the left in left-to-right text and the right in right-to-left text. |
end |
Aligns to the end edge, the opposite of start. |
left / right |
Aligns to the physical left or right edge regardless of text direction. |
center |
Centers each line. |
justify |
Stretches spaces so lines fill the width. The last line is aligned like start (see text-align-last). |
justify-all |
Justifies the last line as well. Support is limited; check a compatibility table. |
match-parent |
Like inherit, except start and end are converted to physical left or right using the parent's direction. |
Usage notes
- Prefer
startandendoverleftandright. They follow the writing direction, so layouts work for both English and Arabic or Hebrew. - Justified text needs hyphenation. In narrow columns it creates large "rivers" of white space. Turn on
hyphens: autowith a properlangattribute, or avoidjustifyon small widths. - Justify and accessibility. Uneven word gaps are hard to read for some people, especially those with dyslexia. Left (start) aligned text is the safest default.
- Centering a block. Use
margin-inline: autoon a box with a width, or flexbox/grid centering.text-alignwill not do it. - Tables and buttons. Table cells and form controls have their own defaults, such as centered
<th>. Set the value explicitly when you need consistency. - Long centered paragraphs. Centered text works for short lines such as headings, but paragraphs of several lines are harder to scan.
Browser support
start, end, left, right, center and justify work in every browser. For justify-all and match-parent, check a compatibility table.
Related
text-align-lastโ aligns the last linetext-indentโ indents the first linehyphensโ helps justified textdirectionโ what start and end mean- Lesson: Styling Text