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

Introduction to Logical Properties and Flow-Relative Values

Understand how logical properties adapt to writing modes and text direction, replacing physical properties like left/right.

Introduction to Logical Properties and Flow-Relative Values

What you'll learn: How to write CSS that automatically adapts to different writing directions without hardcoding left/right or top/bottom positions.

Why Physical Properties Fall Short

Traditionally, CSS uses physical properties like margin-left, padding-right, border-top, and text-align: left. These work fine for English and other left-to-right (LTR) languages. But what happens when your site needs to support Arabic, Hebrew (right-to-left), or Japanese (sometimes vertical)?

Physical properties break down because "left" doesn't mean "start" in all languages. If you set margin-left: 20px to indent the beginning of a paragraph, that margin appears on the wrong side in RTL languages.

Enter Logical Properties

Logical properties use flow-relative directions instead of physical ones:

  • margin-inline-start instead of margin-left (adapts to text direction)
  • margin-inline-end instead of margin-right
  • margin-block-start instead of margin-top (adapts to writing mode)
  • margin-block-end instead of margin-bottom

Think of inline as "along the reading direction" (horizontal in English, vertical in some Japanese layouts) and block as "perpendicular to reading" (vertical in English, stacking paragraphs).

The Power of Adaptation

When you use padding-inline-start: 1rem, it automatically becomes left padding in LTR contexts and right padding in RTL contexts—no extra code needed. The browser handles the adaptation based on the document's dir attribute or CSS direction property.

This approach makes internationalization effortless and keeps your CSS clean and maintainable.

Key Takeaway: Logical properties replace physical directions (left/right/top/bottom) with flow-relative terms (inline-start/inline-end/block-start/block-end) that automatically adapt to different writing modes and text directions.