CSS text-align Property

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

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.

CSS Syntax

syntax.css
text-align: start | end | left | right | center | justify | match-parent | initial | inherit;

Property Values

ValueDescriptionTry it
leftAlign to the physical left edgeTry it
centerCenter inline content in the line boxTry it
rightAlign to the physical right edgeTry it
justifyStretch lines to both edges (last line excluded)Try it
startAlign to the start edge of the writing directionTry it
endAlign to the end edge of the writing directionTry it
match-parentLike inherit, but start/end resolve using the parent’s directionTry it

How to Use text-align

Put it on the block that contains the text you want to align.

  1. Choose a block container (for example p, h1, div, or a table cell).
  2. Set text-align to a keyword such as center or start.
  3. Prefer start / end when the page may use LTR and RTL.
  4. For the last line of justified text, see text-align-last; for spacing details, see text-justify.
PieceRequired?Role
Block containerYesProperty applies to block boxes / table cells
Inline contentYes (to see it)Text or inline-level children get aligned
KeywordYesChooses left, center, start, justify, and so on
direction / langFor start/endLogical edges follow writing direction

Live Preview

Change text-align on the same paragraph. The box width stays fixed so alignment is easy to see.

Only the alignment keyword changes. The paragraph width stays the same.

Paragraph

CSS text-align controls how this sentence sits inside the box. Try each keyword and compare the edges.

text-align: center

CSS Examples

Each snippet focuses on text-align. Extra CSS is kept minimal. Use Try It Yourself for a live editor.

Example 1 — Center Text

Center the inline content inside a block.

CSS
<style>
  p {
    text-align: center;
  }
</style>

<p>This paragraph is centered.</p>
Try It Yourself

How It Works

  1. Target the block. Put text-align on the paragraph (or a parent).
  2. Choose center. Inline content sits in the middle of each line box.
  3. The box stays full width. Only the text alignment changes, not the block’s own size.
  4. 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>
Try It Yourself

How It Works

  1. Set justify. The browser adjusts spacing on full lines.
  2. Edges meet. Left and right sides of wrapped lines line up with the box.
  3. Last line is special. It is not fully justified by default — control it with text-align-last.
  4. 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>
Try It Yourself

How It Works

  1. Use a logical keyword. start means the beginning of the inline direction.
  2. LTR looks like left. In English, start matches the left edge.
  3. RTL flips. With dir="rtl", start matches the right edge.
  4. 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.

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 Chrome All modern
Full support
Mozilla Firefox All modern
Full support
Apple Safari All modern
Full support
Microsoft Edge All modern
Full support
Opera All modern
Full support
Samsung Internet All modern
Full support
Internet Explorer All · limited start/end
Partial
text-align Widely 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.

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.

Next: text-align-last

Learn how to align the last line of a block, especially with justified text.

text-align-last tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful