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.
Fundamentals
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.
Foundation
📝 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
Defaults
🎯 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.
Cheat Sheet
⚡ Quick Reference
Question
Answer
Default value
left (or start based on direction)
Common values
left, center, right, justify
Logical values
start, end
Applies to
Block containers and table cells
Inherited
Yes
Animatable
No
Reference
💎 Property Values
Value
Example
Description
left
text-align: left;
Aligns the text to the left.
right
text-align: right;
Aligns the text to the right.
center
text-align: center;
Centers the text.
justify
text-align: justify;
Stretches lines so each line has equal width, aligning text evenly on both left and right sides.
start
text-align: start;
Aligns text to the start of the block container (left in LTR, right in RTL).
end
text-align: end;
Aligns text to the end of the block container (right in LTR, left in RTL).
leftcenterrightjustifystartend
Context
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.
Preview
👀 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.
Hands-On
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><pclass="center">This paragraph is center-aligned.</p><pclass="justify">This paragraph is justified...</p>
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.
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.
The heading is centered for emphasis while the paragraph remains easy to read with left alignment.
How It Works
Different elements in the same section can use different text-align values for better visual hierarchy.
Companion
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.
Compatibility
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 Chrome1+ · Desktop & Mobile
Full support
Mozilla Firefox1+ · Desktop & Mobile
Full support
Apple Safari1+ · macOS & iOS
Full support
Microsoft Edge12+ · All versions
Full support
Opera3.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 property99% supported
Bottom line:text-align is safe to use everywhere for horizontal text alignment.
Wrap Up
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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about text-align
Use these points when styling text on your next page.
5
Core concepts
★01
left Default
Standard body text.
Default
⚙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.