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.
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-rightinstead 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: rtlin CSS is sufficient (always use the HTMLdirattribute)
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
Related Topics
Language Tags in HTML — The lang Attribute Guide
Web Development
BCP 47 Language Tags — The Web Standard for Locale Identifiers
Standards
CJK Language Codes — Chinese, Japanese, and Korean
Internationalization
ISO 639-1 Overview — Two-Letter Language Codes
Standards
Language Codes in SEO (hreflang) — Multilingual SEO Guide
SEO