Course contentsShow
← Web Development
Lesson 2519 of 2,98245. InternationalizationFree lesson

Logical Properties for Direction Independence

Use CSS logical properties like margin-inline-start instead of margin-left for direction-agnostic layouts.

Logical Properties for Direction Independence

You'll learn how to use CSS logical properties to create layouts that automatically adapt to both left-to-right and right-to-left text directions without extra code.

The Problem with Physical Properties

When you write margin-left: 20px, you're hardcoding a physical direction. In English (LTR), that's the start of a line. In Arabic or Hebrew (RTL), the start is actually on the right. If you've been using properties like margin-left, padding-right, border-top, you're creating layouts that break when the text direction changes.

What Are Logical Properties?

Logical properties describe spacing and positioning relative to the flow of text, not the physical screen edges. Instead of "left" and "right," think "start" and "end." Instead of "top" and "bottom," think "block-start" and "block-end."

Think of it like this: Physical properties are like saying "the door on the north wall." Logical properties are like saying "the door at the entrance"—it automatically adjusts based on which way you're facing.

Key Mappings

  • margin-left → margin-inline-start
  • margin-right → margin-inline-end
  • padding-top → padding-block-start
  • padding-bottom → padding-block-end
  • border-left → border-inline-start
  • text-align: left → text-align: start

The term "inline" refers to the direction text flows (horizontally in most languages), while "block" refers to how blocks stack (vertically in most languages).

Why This Matters

One stylesheet works for all directions. When the dir attribute switches from ltr to rtl, logical properties automatically flip. No duplicate styles, no direction-specific overrides.

Key Takeaway: Use logical properties like margin-inline-start instead of physical properties like margin-left to create truly direction-independent layouts that work seamlessly in both LTR and RTL languages.