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.

Internationalization – `lang` Attribute | HTML Course lesson | BraveProgrammer
  1. Courses
  2. /
  3. HTML Course

Lesson 29 of 55

·HTML

Internationalization – `lang` Attribute and Text Direction

9 min

Course progress53%

What you'll learn

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

5 points
  • Setting `lang` and `dir` on the `<html>` element
  • Overriding language on nested elements
  • Impact on screen readers and search engines
  • Handling right‑to‑left scripts with CSS logical properties
  • Best‑practice for multilingual navigation

Global‑Ready HTML

Declare the page language to improve accessibility and SEO.

<html lang='en' dir='ltr'>
  …
</html>
  • lang – ISO language code (en, fr, ar). Helps screen readers pronounce text correctly and informs search engines.
  • dir – ltr (left‑to‑right) or rtl (right‑to‑left) for scripts like Arabic or Hebrew.

Per‑element overrides

<p>Welcome! <span lang='es'>¡Bienvenido!</span></p>

The <span> tells assistive tech that the inner text is Spanish.

Right‑to‑left considerations

  • Use CSS logical properties (margin-inline-start, padding-inline-end) instead of physical ones (margin-left).
  • Align text with text-align: start to respect the document’s direction.
  • For tables, add dir='rtl' on the <table> if the primary language is right‑to‑left.

Quick checklist for i18n

  1. lang and dir set on <html>? ✅
  2. Language overrides (lang='…') used where needed? ✅
  3. CSS logical properties used for layout? ✅
  4. text-align: start used instead of left/right? ✅
  5. Tested with a screen reader in both LTR and RTL modes? ✅

Tip: For multilingual sites, implement a language switcher that updates the lang attribute and optionally the URL (/en/, /es/).

Make it stickPractice what you've learned1 quiz · 2 practical tests · Optional activities from HTML CourseBrowse activities
Previous lessonAccessibility – ARIA Roles, Live Regions, and Keyboard NavigationContinue to lesson 30HTML5 Geolocation APIBack to HTML Course curriculum