The text-align property sets the horizontal alignment of inline-level content inside a block container or table cell. Think of it as the horizontal partner of vertical-align.
It is inherited. The modern initial value is start (follows direction). Physical keywords (left, right) stay fixed; logical keywords (start, end) flip with writing direction. It does not center the block box itself.
Baseline · Widely available.
Not deprecated. Prefer standard keywords. Non-standard: avoid -moz-center / -webkit-center — use center instead. Use justify carefully for readability.
Syntax
CSS Syntax
syntax.css
text-align:start | end | left | right | center | justify | match-parent | initial | inherit;
Target the block. Put text-align on the paragraph (or a parent).
Choose center. Inline content sits in the middle of each line box.
The box stays full width. Only the text alignment changes, not the block’s own size.
Inherited by children. Nested inline content follows the same alignment unless overridden.
Example 2 — Justify Lines
Stretch multi-line text so both edges look even.
CSS
<style>
p {
text-align: justify;
}
</style>
<p>
Justified text spreads spaces so full lines meet both edges.
The last line usually stays start-aligned.
</p>
Justified text spreads spaces so full lines meet both edges. The last line usually stays start-aligned. Narrow columns can look uneven, so use justify with care.
How It Works
Set justify. The browser adjusts spacing on full lines.
Edges meet. Left and right sides of wrapped lines line up with the box.
Last line is special. It is not fully justified by default — control it with text-align-last.
Mind readability. Uneven gaps can be harder to read; avoid justify in very narrow columns.
Example 3 — Logical Start
Align to the start edge so LTR and RTL both feel natural.
CSS
<style>
p {
text-align: start;
}
</style>
<p>Start aligns with the writing direction.</p>
<p dir="rtl">في العربية، البداية على اليمين.</p>
Use a logical keyword.start means the beginning of the inline direction.
LTR looks like left. In English, start matches the left edge.
RTL flips. With dir="rtl", start matches the right edge.
Better than hard-coded left. One rule works for both directions.
Edge Cases & Pitfalls
If alignment looks wrong, one of these is usually why.
block
Does not center the box itself
text-align: center centers text inside the element. To center a block horizontally, use margin-inline: auto, flexbox, or grid on the parent.
logical
left / right do not flip in RTL
Physical edges stay fixed. Prefer start / end when layout must follow direction.
justify
Justify can hurt readability
Uneven word gaps may be harder for some readers. Avoid justify in narrow columns; tune last-line behavior with text-align-last.
inherit
It is inherited
Setting text-align on a parent affects nested blocks and cells unless a child overrides it.
vendor
Skip vendor-prefixed center
-moz-center and -webkit-center are non-standard. Use the standard center keyword.
Compatibility
Browser Support
text-align is a browser CSS property for inline content alignment. Node.js, Deno, and Bun do not apply it.
✓ Baseline · Widely available
text-align
left, right, center, and justify are universal. start and end are widely supported in modern browsers. match-parent is newer than the core set.
98%Core keyword support
Google ChromeAll modern
Full support
Mozilla FirefoxAll modern
Full support
Apple SafariAll modern
Full support
Microsoft EdgeAll modern
Full support
OperaAll modern
Full support
Samsung InternetAll modern
Full support
Internet ExplorerAll · limited start/end
Partial
text-alignWidely supported
Bottom line: Safe to teach for left, right, center, and justify everywhere. Prefer start/end in modern multilingual pages. It is not a runtime API.
Remember
Key Takeaways
Role: align inline content horizontally inside a block or cell.
Physical vs logical: left/right stay fixed; start/end follow direction.
Not for boxes: use margin/flex/grid to center the element itself.
justify: even edges, but watch word spacing and accessibility.
One line: put text-align on the block that holds the text — it moves the content, not the box.
Frequently Asked Questions
It sets the horizontal alignment of inline-level content inside a block container or table cell, such as text in a paragraph.
The modern initial value is start, which follows the writing direction (left in LTR, right in RTL). Older engines may behave like left or right based on direction.
left always uses the physical left edge. start uses the start edge of the text direction, so it flips in RTL.
No. It aligns inline content inside the box. To center the box itself, use margin: auto, flexbox, or grid on the parent.
Use it carefully. Uneven word spacing from justify can be harder to read for some people, including those with dyslexia. Prefer left or start for body text when unsure.
Core values are Baseline Widely available. start and end are widely supported in modern browsers. It is a browser CSS property, not a Node.js feature.