--- title: "RTL and bidirectional text" category: i18n status: recommended url: https://webspecification.com/spec/i18n/rtl-support/ updated: "2026-07-09T00:00:00.000Z" sources: - title: "W3C i18n — Structural markup and right-to-left text in HTML" url: "https://www.w3.org/International/questions/qa-html-dir" publisher: "W3C" - title: "W3C i18n — Inline markup and bidirectional text in HTML" url: "https://www.w3.org/International/articles/inline-bidi-markup/" publisher: "W3C" - title: "MDN — CSS logical properties and values" url: "https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Logical_properties_and_values" publisher: "MDN" source_repo: undefined licence: CC-BY-4.0 --- # RTL and bidirectional text > Sites that serve Arabic, Hebrew, Persian, or Urdu must set dir="rtl" and use CSS logical properties so layouts mirror correctly without hard-coded left and right. ## What it is Right-to-left (RTL) scripts — Arabic, Hebrew, Persian, Urdu, Pashto, Dhivehi, and others — read from right to left. So do their layouts: the logo sits on the right, navigation flows right-to-left, scrollbars are on the left, and progress indicators advance leftwards. Bidirectional ("bidi") text is content that mixes RTL and LTR runs, for example an English brand name embedded inside an Arabic paragraph. The HTML `dir` attribute declares direction. The Unicode Bidirectional Algorithm handles inline mixing automatically when `dir` is set correctly. Direction does not follow from language. `lang` and `dir` are independent attributes: a browser handed `lang="ar"` with no `dir` still lays the page out left to right. `lang` names the language so pronunciation, spellcheck, and font selection are right; `dir` sets the direction. An RTL page needs both, which is why every example here carries `lang` and `dir` together. ```html ``` ## Why it matters For roughly half a billion readers, an LTR-only layout looks broken: cramped, misaligned, with arrows and icons pointing the wrong way. Get direction wrong and you also break the bidi algorithm — phone numbers, dates, and Latin brand names appear in the wrong order inside RTL paragraphs. Setting `dir` correctly fixes most of this without any per-element work. ## How to implement **Set direction on ``.** Use `dir="rtl"` on the root for RTL locales. Set `dir="auto"` on user-generated content (comments, messages) so the browser picks direction from the first strong character. This matters even when the interface itself is English-only and never localised. A reader on an `en-US` system can still type Arabic into a comment box, chat field, or note editor; `dir="auto"` on every free-form text input and `