Guide · Arabic & RTL

Arabic websites without a second stylesheet.

Most RTL bugs come from CSS written for one direction. Set the direction in markup, write spacing as start and end instead of left and right, and isolate text you did not write. Here is what each rule does in a real browser.

Updated 16 November 2026Sources checked 16 November 2026Reviewed by Eng. Hasan Kassas

The short answer

Put lang="ar" and dir="rtl" on the html element of every Arabic page, not a CSS direction rule: the W3C recommends markup because direction is part of the content, not decoration. Then write your CSS with logical properties (margin-inline-start, padding-inline-end, inset-inline-start) and the same stylesheet lays out correctly in both languages.

Text you do not control, such as user names, product titles and phone numbers, needs isolation so it cannot reorder the sentence around it. Use <bdi> or dir="auto" for it, and dir="ltr" on inputs for phone numbers, card numbers and codes. Everything below was checked in Chrome 157 with a test page on 16 November 2026.

Physical vs logical

CSS that flips with the page

In an RTL pageLogical version
margin-left: 16pxStays on the left (does not flip)margin-inline-start: 16px
padding-right: 8pxStays on the rightpadding-inline-end: 8px
border-left: 4px solidStays on the leftborder-inline-start: 4px solid
left: 0 (positioned)Stays on the leftinset-inline-start: 0
direction: rtl in CSSWorks visually, but the direction is lost if the CSS does not loaddir="rtl" on the html element
dir="ltr" on a phone fieldArabic digits with spaces (٠٩٣٣ ١٢٣ ٤٥٦) still show in reverse group orderdir="ltr" plus unicode-bidi: isolate-override
Tested page

The test page

This is the exact page our browser test loads and measures. Use it as a starting point, or open it with dir="ltr" to see the same CSS lay out for English.

<!doctype html>
<html lang="ar" dir="rtl">
<head>
  <meta charset="utf-8">
  <style>
    .card  { margin-inline-start: 16px; padding-inline-end: 8px; border-inline-start: 4px solid; }
    .old   { margin-left: 16px; }                      /* physical: stays on the left in RTL */
    .badge { position: absolute; inset-inline-start: 0; top: 0; }
    .wrap  { position: relative; width: 400px; height: 40px; }
    .tel   { unicode-bidi: isolate-override; }    /* keeps ٠٩٣٣ ١٢٣ ٤٥٦ in typed order */
  </style>
</head>
<body style="margin:0; width:400px">
  <div class="card" id="card">بطاقة</div>
  <div class="old" id="old">بطاقة</div>
  <div class="wrap" id="wrap"><span class="badge" id="badge">جديد</span></div>
  <p dir="auto" id="auto">Hello مرحبا</p>
  <input type="tel" dir="ltr" id="phone" value="+963 933 123 456">
  <p><span dir="ltr" id="digits">٠٩٣٣ ١٢٣ ٤٥٦</span></p>
  <p><span dir="ltr" class="tel" id="digits-fixed">٠٩٣٣ ١٢٣ ٤٥٦</span></p>
  <p id="price">السعر: <bdi id="name">iPhone 13</bdi> فقط</p>
</body>
</html>

The test checks 13 things on this page in headless Chrome 157: the four logical properties above, that margin-left does not flip, that dir="auto" on "Hello مرحبا" resolves to LTR, that the tel input stays LTR, that <bdi> computes to unicode-bidi: isolate, and the Arabic-digit case below.

Plain text

Mixed Arabic and English where there is no HTML

Push notifications, SMS, page titles and CSV exports have no dir attribute. Decide the direction from the first strong letter, the same rule the browser applies for dir="auto", and wrap inserted text in the Unicode isolate characters FSI and PDI:

// Mixed Arabic + English text: find a string's direction and isolate it so it
// cannot reorder the sentence around it (same rule the browser uses for dir="auto").
const RTL_CHAR = /[֐-ࣿיִ-﷿ﹰ-]/; // Hebrew, Arabic, Syriac, Thaana, presentation forms
const LTR_CHAR = /[A-Za-zÀ-ɏͰ-ϿЀ-ӿ]/;

function firstStrongDir(text) {
  for (const ch of String(text)) {
    if (RTL_CHAR.test(ch)) return "rtl";
    if (LTR_CHAR.test(ch)) return "ltr";
  }
  return null; // only digits, spaces, punctuation: let the paragraph decide
}

// For plain-text places (SMS, push, notifications, <title>): wrap in FSI ... PDI.
const isolate = (text) => "⁨" + text + "⁩";

firstStrongDir("2026 آيفون"); // "rtl": digits are weak, the first letter decides

Tested with 6 cases: Arabic first, Latin first, digits before Arabic, a phone number on its own (no strong letter, returns null), an Arabic presentation form, and the isolate wrapper.

Checklist

Before you ship an Arabic page

  • html has lang="ar" and dir="rtl". Screen readers use lang to pick an Arabic voice; the browser uses dir for layout, form fields and scrollbars.
  • No left or right in spacing, borders or positioning that should follow the reading direction. Search the CSS for margin-left, padding-right, left: and text-align: left.
  • Directional icons (back, next, chevrons) are mirrored in RTL; logos, media play buttons and check marks are not.
  • Names, titles and anything typed by users sit inside <bdi> or an element with dir="auto", so an English product name at the end of an Arabic sentence does not drag the full stop to the wrong side.
  • Phone, card, IBAN and code inputs have dir="ltr" and unicode-bidi: isolate-override. dir alone is not enough for Arabic digits: typed as ٠٩٣٣ ١٢٣ ٤٥٦, the groups display in reverse order, because the bidi algorithm treats Arabic-Indic digits like right-to-left text when it resolves the spaces between them. Our test measures both. To validate Syrian numbers, use the phone number checker.
  • Numbers and dates use the right locale. ar-SY gives Arabic-Indic digits and Syrian month names; see the dates guide.
  • Test at 360px wide in both directions. Overflow and clipped labels show up first on small Arabic screens, where words are often longer.
FAQ

Common questions

Use the dir attribute on the html element. The W3C advises markup because the direction belongs to the content, and it still applies if the stylesheet fails to load.

Sources

Where these facts come from

  1. CSS logical properties and valuesMDN Web Docs · accessed 16 Nov 2026
  2. The dir global attributeMDN Web Docs · accessed 16 Nov 2026
  3. <bdi>: the bidirectional isolate elementMDN Web Docs · accessed 16 Nov 2026
  4. Structural markup and right-to-left text in HTMLW3C Internationalization · accessed 16 Nov 2026
  5. Inline markup and bidirectional text in HTMLW3C Internationalization · accessed 16 Nov 2026
  6. UAX #9: Unicode Bidirectional AlgorithmUnicode Consortium · accessed 16 Nov 2026

Behaviour measured in headless Chrome 157 on 16 November 2026. Logical properties are supported in all current major browsers; check the MDN compatibility tables if you support old devices.

Need an Arabic site that does not break?

We build bilingual sites and apps for Syrian businesses. Tell us what you have.