Arabic engineering reference
Arabic Language Codes: lang, dir and hreflang
Use lang="ar" to identify Arabic content and dir="rtl" to set its base direction; neither attribute replaces the other. Regional tags such as ar-JO describe a more specific localization. This reference shows valid tag construction, nested language changes, and alternate-page links while keeping language, region, and layout separate.
Arabic and regional tags
BCP 47 combines the registered language subtag ar with an optional registered region subtag. The conventional casing below uses lowercase language and uppercase region. A regional tag identifies localization, not a separate writing direction or an instruction to translate content.
| Tag | Region or language | Suggested use |
|---|---|---|
| ar | Arabic | General Arabic content without a regional distinction |
| ar-SA | Saudi Arabia | Arabic content specifically localized for Saudi Arabia |
| ar-EG | Egypt | Arabic content specifically localized for Egypt |
| ar-AE | United Arab Emirates | Arabic content specifically localized for the UAE |
| ar-JO | Jordan | Arabic content specifically localized for Jordan |
| ar-MA | Morocco | Arabic content specifically localized for Morocco |
| ar-KW | Kuwait | Arabic content specifically localized for Kuwait |
| ar-QA | Qatar | Arabic content specifically localized for Qatar |
| ar-LB | Lebanon | Arabic content specifically localized for Lebanon |
Set language and direction independently
HTML lang describes content language and inherits to descendants. dir sets directionality. For a predominantly Arabic document set both on the root. For an Arabic passage in an English document, scope both attributes to that passage.
Guidance: choose ar for shared Arabic content unless you actually maintain a region-specific version. A regional tag is not a guarantee of a specific numbering system; configure number formatting separately.
<html lang="ar-JO" dir="rtl">
<head><title>Arabic page</title></head>
<body>
<p>Arabic content</p>
<code lang="en" dir="ltr">npm install</code>
</body>
</html>Describe alternate pages with hreflang
The hreflang attribute is a language hint for the linked resource. Use actual alternate pages; do not invent regional URLs for identical content merely because the tag exists. The following paths are illustrative and must be replaced with your real alternate URLs.
<link rel="alternate" hreflang="ar" href="https://example.com/ar/guide">
<link rel="alternate" hreflang="en" href="https://example.com/en/guide">Keep localization decisions explicit
lang does not set right-to-left layout. dir does not declare the language. hreflang describes a linked page, not the language of the current document. Keep these responsibilities separate in templates and content models so an English code sample can remain left-to-right within an Arabic page.
Related references and tools
- Arabic Digits: Unicode and JavaScript Reference
- Arabic Tashkeel: Diacritics and Removal Regex
- Arabic Unicode Ranges: Blocks, Regex and Font Subsets
- Arabic Letter Forms: 28 Letters and Joining Rules
- Arabic Numeral Converter
- Arabic Text Normalizer
- Arabic Regex Patterns
- Arabic Search Normalization
- What lang="ar" and dir="rtl" each do
Questions and answers
Does lang="ar" make a page right-to-left?
No. The lang attribute declares the language of the content. Use dir="rtl" independently to establish the right-to-left base direction for an Arabic document or passage.
When should I choose ar-JO instead of ar?
Use ar-JO for content specifically localized for Jordan. Use ar for shared Arabic content when you do not maintain a meaningful regional distinction.