Course contentsShow
← Web Development
Lesson 463 of 2,9828. Advanced CSS Selectors and FeaturesFree lesson

Logical Text Alignment

Use text-align: start/end instead of left/right for alignment that adapts to text direction automatically.

Logical Text Alignment

You'll learn how to align text in a way that automatically adapts to different writing directions.

The Core Idea

Until now, you've probably used text-align: left and text-align: right to position text within elements. But here's the problem: these values are physical directions. In languages that read right-to-left (like Arabic or Hebrew), "left" and "right" don't respect the natural reading flow.

Logical text alignment solves this by using start and end instead:

  • text-align: start aligns text to the beginning of the reading direction
  • text-align: end aligns text to the end of the reading direction

Think of it like giving directions: instead of saying "turn left" (which only works if you're facing a certain way), you say "turn toward the entrance" — it works no matter which way you're oriented.

How It Works

.content {
  text-align: start; /* Left in LTR, right in RTL */
}

.button {
  text-align: end; /* Right in LTR, left in RTL */
}

In a left-to-right language (like English), start behaves like left and end behaves like right. But in a right-to-left language, they automatically flip. You write the CSS once, and it adapts to the document's text direction set by the dir attribute in your HTML.

Why This Matters

Just like margin-inline-start replaced margin-left for logical spacing, text-align: start replaces text-align: left for truly international, flow-relative layouts. It's part of building components that respect every user's language and reading direction without extra code.

Key Takeaway: Use text-align: start and text-align: end instead of left/right to create text alignment that automatically adapts to any text direction, making your site more accessible and globally ready.