CSS
🎯 CSS text-align Property (Horizontal Text Alignment)
The text-align property in CSS defines how text is aligned horizontally inside an HTML element.
It controls whether text is aligned to the left, right, center, or justified across both sides of a container.
🔹 Basic Usage
p {
text-align: center;
}
➡️ In this example, the text inside the paragraph is centered horizontally.
🔸 Values and Their Meanings
1. left
Aligns text to the left side of the container.
p {
text-align: left;
}
➡️ This is the default alignment in most web browsers.
2. right
Aligns text to the right side of the container.
➡️ Commonly used for dates, signatures, or design layouts.
3. center
Centers the text horizontally inside the element.
p {
text-align: center;
}
➡️ Often used for headings, titles, and hero sections.
4. justify
Aligns text evenly on both left and right edges.
➡️ Creates a clean newspaper-style paragraph layout.
p {
text-align: justify;
}
5. initial
Resets the alignment to the browser’s default value (usually left).
6. inherit
The element inherits the text alignment from its parent element.
💡 Summary Table
| Value | Description |
|---|---|
| left | Aligns text to the left |
| right | Aligns text to the right |
| center | Centers the text horizontally |
| justify | Aligns text evenly on both sides |
| initial | Resets to default alignment |
| inherit | Inherits alignment from parent |
-
🧠 Summary
- The text-align property controls horizontal alignment of text inside an element.
- Main alignment options:
- left → default alignment
- right → right alignment
- center → centered text
- justify → full-width alignment
- This property is widely used in layouts, typography, and UI design for better readability and visual balance.
