Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Logical Properties & Writing | CSS Basics to Advanced lesson | BraveProgrammer
  1. Courses
  2. /
  3. CSS Basics to Advanced

Lesson 26 of 50

·css

Logical Properties & Writing Modes

7 mins

Course progress52%

What you'll learn

Keep these ideas in mind as you work through the lesson.

2 points
  • Logical properties (`margin-inline`, `padding-block`) make internationalization easier.
  • `writing-mode` is used for Asian vertical scripts and certain UI components.

Logical properties let you write direction‑agnostic CSS, which is essential for multilingual sites that support right‑to‑left (RTL) scripts.

Physical vs Logical

PhysicalLogical
margin-leftmargin-inline-start
margin-rightmargin-inline-end
margin-topmargin-block-start
margin-bottommargin-block-end

When the element’s direction (ltr or rtl) changes, the logical properties automatically map to the correct physical side.

Example – Bi‑directional Card

.card {
  padding-inline: 1.5rem;   /* left in LTR, right in RTL */
  padding-block: 1rem;      /* top & bottom stay the same */
}

Writing Modes

writing-mode controls the flow of text:

  • horizontal-tb – default (left‑to‑right horizontally, top‑to‑bottom).
  • vertical-rl – characters flow top‑to‑bottom, columns progress right‑to‑left (common in Japanese).
  • vertical-lr – top‑to‑bottom, columns left‑to‑right.

Real‑World Scenario – Language Switcher

<body dir="ltr"> … </body>
<body dir="rtl"> … </body>
/* Global layout uses logical margins */
.container { margin-inline: auto; max-width: 80ch; }

The container stays centered regardless of direction.


Accessibility Tip

When you set direction on an element, also set lang attribute (<html lang="ar" dir="rtl">). Screen readers use lang for proper pronunciation.

Make it stickPractice what you've learned1 quiz · 6 practical tests · Optional activities from CSS Basics to AdvancedBrowse activities
Previous lessonCSS Functions – calc(), clamp(), min(), max()Continue to lesson 27CSS Grid – FundamentalsBack to CSS Basics to Advanced curriculum