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 CSS for Internationa | CSS Basics to Advanced lesson | BraveProgrammer
  1. Courses
  2. /
  3. CSS Basics to Advanced

Lesson 45 of 50

·css

Logical CSS for Internationalization

7 mins

Course progress90%

What you'll learn

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

3 points
  • Combine `dir`, `writing-mode`, and logical properties to build multilingual layouts.
  • If the element has `dir="rtl"`, `margin-inline-start` becomes the right margin.
  • Always set `lang` on the `<html>` element for screen readers.

Internationalisation (i18n) goes beyond translation – the layout must adapt to reading direction (LTR vs RTL) and sometimes to vertical scripts.

Core Tools

  • dir attribute – tells the browser the base direction (dir="rtl" or dir="ltr").
  • Logical properties – margin-inline-start, padding-block-end, etc.
  • unicode-bidi – controls how mixed‑direction text is displayed (unicode-bidi:plaintext).
  • writing-mode – for vertical scripts (vertical-rl, vertical-lr).

Example – Bidirectional Navigation

<nav class="nav" dir="ltr">
  <a href="#" class="nav__link">Home</a>
  <a href="#" class="nav__link">About</a>
</nav>
.nav { display:flex; gap:1rem; }
/* When the parent switches to rtl, margins adapt automatically */
.nav__link { margin-inline-start:1rem; }

CSS‑Only Direction Switcher

html[lang="ar"] { direction:rtl; }
html[lang="en"] { direction:ltr; }

Now just changing the lang attribute on <html> flips the whole layout.

Handling Images & Icons

Prefer SVG icons that can be mirrored with transform:scaleX(-1) when dir:rtl.

[dir="rtl"] .icon { transform:scaleX(-1); }

Accessibility Checklist

  • Always set the lang attribute on the <html> element – it guides screen readers.
  • Use unicode-bidi: plaintext on blocks that contain mixed LTR/RTL text to preserve the intended order.
  • Test with both LTR and RTL languages – crucial for padding/margin that rely on logical properties.

Real‑World Tip – Avoid Hard‑Coded Offsets

Never write margin-left:20px for a UI that might be mirrored. Use margin-inline-start instead. This prevents UI breakage when the site is viewed in Arabic, Hebrew, or Persian.

Browser Compatibility

Logical properties are fully supported in Chrome 84+, Edge 84+, Safari 13+, and Firefox 68+. Older browsers fallback gracefully to physical properties.

Pro Tip – Use a CSS Variable for the direction‑dependent size

:root { --spacing-inline:1rem; }
[dir="rtl"] { --spacing-inline:2rem; }
.element { margin-inline-start: var(--spacing-inline); }

Now you can tweak the spacing per direction without rewriting every selector.

Make it stickPractice what you've learned1 quiz · 6 practical tests · Optional activities from CSS Basics to AdvancedBrowse activities
Previous lessonCSS Houdini – The Paint APIContinue to lesson 46CSS for Dark Mode & ThemingBack to CSS Basics to Advanced curriculum