Right-to-Left (RTL) Languages — Codes and Web Implementation

Complete guide to right-to-left language codes (Arabic, Hebrew, Urdu, etc.) and implementing bidirectional text support in web applications.

Internationalization

Detailed Explanation

RTL Languages in Web Development

Right-to-left (RTL) languages present unique challenges for web developers. Understanding which language codes correspond to RTL scripts is essential for building truly international applications.

RTL Language Codes

The following languages use right-to-left scripts:

Code Language Script
ar Arabic Arabic
he Hebrew Hebrew
fa Persian (Farsi) Arabic
ur Urdu Arabic
ps Pashto Arabic
sd Sindhi Arabic
ug Uyghur Arabic
yi Yiddish Hebrew
dv Divehi Thaana
ku Kurdish (Sorani) Arabic

HTML Implementation

Set both lang and dir attributes:

<html lang="ar" dir="rtl">

For mixed-direction content, use the dir attribute on individual elements:

<p dir="rtl" lang="ar">مرحبا بالعالم</p>
<p dir="ltr" lang="en">Hello World</p>

CSS Logical Properties

Modern CSS uses logical properties that automatically adapt to text direction:

/* Instead of margin-left, use: */
.sidebar { margin-inline-start: 1rem; }

/* Instead of padding-right, use: */
.content { padding-inline-end: 2rem; }

/* Instead of text-align: left, use: */
.heading { text-align: start; }

/* Instead of border-left, use: */
.card { border-inline-start: 3px solid blue; }

Bidirectional Text (Bidi)

When LTR and RTL text are mixed, the Unicode Bidirectional Algorithm handles ordering. Use the <bdi> element to isolate text whose direction is unknown:

<p>المستخدم: <bdi>user123</bdi> قام بالتسجيل</p>

Common Pitfalls

  • Hardcoding margin-left/padding-right instead of using logical properties
  • Forgetting to mirror icons and directional indicators
  • Not testing with actual RTL content (using placeholder text misses real issues)
  • Assuming direction: rtl in CSS is sufficient (always use the HTML dir attribute)

Use Case

Any web application that serves users who read Arabic, Hebrew, Persian, Urdu, or other RTL languages must implement proper bidirectional support. This includes e-commerce platforms, social media apps, government portals, and content management systems operating in the Middle East, North Africa, or South Asia.

Try It — Language Code Reference

Open full tool