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.

Arabic and regional tags
TagRegion or languageSuggested use
arArabicGeneral Arabic content without a regional distinction
ar-SASaudi ArabiaArabic content specifically localized for Saudi Arabia
ar-EGEgyptArabic content specifically localized for Egypt
ar-AEUnited Arab EmiratesArabic content specifically localized for the UAE
ar-JOJordanArabic content specifically localized for Jordan
ar-MAMoroccoArabic content specifically localized for Morocco
ar-KWKuwaitArabic content specifically localized for Kuwait
ar-QAQatarArabic content specifically localized for Qatar
ar-LBLebanonArabic 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

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.

Sources