CSS text-align Property

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 4 Examples
Typography

What You’ll Learn

The text-align property controls how text is aligned horizontally inside block-level elements like paragraphs, headings, and divs.

01

left

Default align.

02

center

Middle align.

03

right

End side.

04

justify

Even edges.

05

start / end

Direction-aware.

06

Inline content

Text inside box.

Introduction

The text-align property in CSS is used to set the horizontal alignment of text within an element. This property is commonly applied to block-level elements like paragraphs and headings to control the alignment of their text content.

The text-align property can take several values, allowing for versatile text alignment options that enhance the readability and visual appeal of your web pages.

Definition and Usage

Apply text-align to the container element that holds the text. It affects inline content such as text, images, and inline elements inside that block.

Use center for headings and hero text, left or start for body copy, and justify for long paragraphs that should fill the full line width.

💡
Beginner Tip

text-align moves text inside an element. It does not move the element itself on the page. To center a box, use layout tools like margin: 0 auto or flexbox.

📝 Syntax

The syntax for the text-align property is simple. It is applied to an element using the following format:

syntax.css
element {
  text-align: value;
}

Here, value can be one of the predefined keywords that specify the alignment.

Basic Example

center-text.css
p {
  text-align: center;
}

Syntax Rules

  • Apply the property to the block container, not to each word individually.
  • The property is inherited, so child elements receive the same alignment unless overridden.
  • Use logical values start and end for multilingual and RTL-friendly layouts.
  • justify works best on paragraphs with enough text to fill multiple lines.

Related Properties

  • text-align-last — aligns the last line of a block
  • line-height — controls vertical spacing between lines
  • direction — sets text direction for RTL layouts

🎯 Default Value

The default value of the text-align property is left. This means that, unless otherwise specified, text within block-level elements is aligned to the left in left-to-right languages.

⚡ Quick Reference

QuestionAnswer
Default valueleft (or start based on direction)
Common valuesleft, center, right, justify
Logical valuesstart, end
Applies toBlock containers and table cells
InheritedYes
AnimatableNo

💎 Property Values

ValueExampleDescription
lefttext-align: left;Aligns the text to the left.
righttext-align: right;Aligns the text to the right.
centertext-align: center;Centers the text.
justifytext-align: justify;Stretches lines so each line has equal width, aligning text evenly on both left and right sides.
starttext-align: start;Aligns text to the start of the block container (left in LTR, right in RTL).
endtext-align: end;Aligns text to the end of the block container (right in LTR, left in RTL).
left center right justify start end

When to Use text-align

text-align is one of the most common typography properties on the web:

  • left / start — Body paragraphs, articles, and form labels in LTR layouts.
  • center — Headings, hero sections, captions, and call-to-action text.
  • right / end — Price labels, metadata, and numeric columns in some designs.
  • justify — Long-form content such as blog posts or documentation paragraphs.
  • table cells — Align content inside th and td elements.

👀 Live Preview

See how the same paragraph changes with different text-align values:

left

This paragraph is aligned to the left side of its container.

center

This paragraph is centered horizontally.

right

This paragraph is aligned to the right side.

justify

This paragraph is justified. Justification stretches the lines so that each line has equal width, aligning the text evenly on both the left and right sides when there is enough text.

Examples Gallery

Start with center and justify from the reference example, then explore left/right alignment, logical values, and a common heading plus body pattern.

📜 Basic Text Alignment

Center-align and justify text within paragraphs — matching the reference example.

Example 1 — Center and justify paragraphs

In this example, we’ll demonstrate how to center-align and justify text within a paragraph.

index.html
<style>
  .center {
    text-align: center;
  }
  .justify {
    text-align: justify;
  }
</style>

<p class="center">This paragraph is center-aligned.</p>
<p class="justify">This paragraph is justified...</p>
Try It Yourself

How It Works

Each class applies a different alignment keyword to the paragraph’s inline content.

Example 2 — Left and right alignment

Use text-align: left for standard body text and text-align: right for metadata or prices.

left-right.css
.article-body { text-align: left; }
.price-tag { text-align: right; }
Try It Yourself

How It Works

Left and right are physical directions. They stay the same regardless of document writing direction.

📄 Layout Patterns

Use logical values for multilingual pages and combine alignments in real UI patterns.

Example 3 — Logical start and end values

Use start and end when your site supports both LTR and RTL languages.

logical-align.css
.intro { text-align: start; }
.footnote { text-align: end; }
Try It Yourself

How It Works

Logical keywords adapt to the writing direction set by direction or the document language.

Example 4 — Centered heading with left-aligned body

A common pattern: center the title, keep paragraph text left-aligned for readability.

article-layout.css
.article-title {
  text-align: center;
}

.article-body {
  text-align: left;
  max-width: 42rem;
  margin: 0 auto;
}
Try It Yourself

How It Works

Different elements in the same section can use different text-align values for better visual hierarchy.

text-align in the family

text-align handles horizontal alignment of inline content. Pair it with line-height for readable line spacing and text-align-last when you need special control over the final line of a paragraph.

readable-text.css
.article {
  text-align: left;
  line-height: 1.6;
}

🧠 How text-align Works

1

Block container holds inline content

A paragraph, heading, or div creates a block box that contains text and inline elements.

Container
2

text-align sets horizontal position

The chosen keyword tells the browser where to place inline content within the line box.

CSS rule
3

Lines render with alignment

Each line of text follows the alignment. With justify, spacing expands between words to fill the width.

Rendering
=

Readable, structured text

Headings, paragraphs, and table cells display with clear horizontal alignment.

Browser Compatibility

The text-align property is widely supported across all major browsers, including Chrome, Firefox, Safari, Edge, and Opera. It is a well-established property in CSS, ensuring consistent behavior across different browsing environments.

Baseline · Universal support

One of CSS’s core properties

text-align has been supported since the earliest CSS implementations in all major browsers.

99% Modern browser support
Google Chrome 1+ · Desktop & Mobile
Full support
Mozilla Firefox 1+ · Desktop & Mobile
Full support
Apple Safari 1+ · macOS & iOS
Full support
Microsoft Edge 12+ · All versions
Full support
Opera 3.5+ · Modern versions
Full support

Testing tip

Test start and end with direction: rtl; on a container to confirm logical alignment flips correctly.

text-align property 99% supported

Bottom line: text-align is safe to use everywhere for horizontal text alignment.

Conclusion

The text-align property is a fundamental tool for web developers to control the alignment of text within block-level elements.

Whether you need left, right, center, or justified text alignment, this property offers the flexibility to create visually appealing and readable content. Experiment with different alignment options to see how they can enhance the layout and design of your web pages.

💡 Best Practices

✅ Do

  • Use left or start for long body paragraphs
  • Center short headings, titles, and hero text when it fits the design
  • Use start and end for multilingual sites
  • Apply alignment to table cells for cleaner data presentation
  • Combine centered titles with left-aligned body text for readability

❌ Don’t

  • Center large blocks of body text — it reduces readability
  • Use text-align to center block elements themselves
  • Justify very narrow columns where word spacing looks uneven
  • Forget that alignment is inherited by child elements

Key Takeaways

Knowledge Unlocked

Five things to remember about text-align

Use these points when styling text on your next page.

5
Core concepts
02

Inline content

Aligns inside box.

Scope
03

center

Headings & heroes.

Common
04

justify

Even both edges.

Mode
🔄 05

line-height

Pair for readability.

Companion

❓ Frequently Asked Questions

text-align sets the horizontal alignment of inline content inside a block-level element, such as text inside a paragraph or heading.
The default value is left in most left-to-right languages. In right-to-left documents, the initial alignment follows the writing direction.
left always aligns to the physical left side. start aligns to the beginning of the text direction, which is left in LTR and right in RTL.
No. text-align centers inline content inside the element. To center a block element horizontally, use margin: auto or flexbox on the parent.
Use justify for multi-line paragraphs where you want even left and right edges. Avoid it for very narrow columns or short text blocks because spacing can look uneven.

Practice in the Live Editor

Open the HTML editor and try text-align: center; on a heading and text-align: justify; on a paragraph.

HTML Editor →

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.

5 people found this page helpful