CSS Tutorial: text-align 🧭✨

Introduction to text-align in CSS πŸ“

The text-align property controls the horizontal alignment of inline content (like text) inside a block-level element. It’s one of the simplest yet most frequently used CSS properties β€” perfect for headings, paragraphs, navigation items, and more! 🎯

Why Use text-align? πŸ€”

  • To center headings or banners 🎯
  • To align paragraphs for better readability πŸ“–
  • To right-align numbers or UI text πŸ”’
  • To create flexible and elegant layouts ✨

Syntax πŸ“Œ

Basic Syntax

selector {
  text-align: left | right | center | justify | start | end;
}

Note

Note: text-align affects inline-level content inside a block container.

Available Values 🧩

1. left (Default in LTR languages) ⬅️

Aligns text to the left edge.

2. right ➑️

Aligns text to the right edge. Useful for UI labels or numbers.

3. center 🎯

Centers the inline content inside the container.

4. justify πŸ“š

Stretches each line so text touches both left and right sides β€” commonly used in books and newspapers.

5. start ↖️

Aligns text according to writing direction: left for LTR, right for RTL.

6. end ↗️

Opposite of start, aligns text based on writing direction.

Examples πŸ”₯

1. Basic Alignment

Left, Right, Center

h1 {
  text-align: center;
}

p {
  text-align: left;
}

.price {
  text-align: right;
}

2. Justified Paragraph

Justified text

.article {
  text-align: justify;
}

3. Direction-aware Alignment 🌍

Start & End

.dynamic {
  text-align: start;
}

Comparison Table πŸ“š

ValueDescription
leftAligns text to the left
rightAligns text to the right
centerCenters text
justifyStretches text to fill width
startAligns based on writing mode (LTR/RTL)
endOpposite of start

Visual Example πŸ–ΌοΈ

Here’s a visual placeholder showing different text alignments:

>>β€œAlignment is the silent force that shapes readability and visual harmony.” ✨

Conclusion πŸŽ‰

The text-align property is a simple yet powerful tool for controlling text alignment in CSS. Whether you’re crafting clean UI layouts or designing readable article content, mastering text alignment will elevate your typography and design skills. Start experimenting with it β€” especially center and justify β€” to bring balance and beauty to your layouts! πŸš€