RTL Web Localization for Arabic and Hebrew Sites

RTL Web Localization for Arabic and Hebrew Sites

Right-to-left is a document-direction decision, not a translated mirror. The bidi model, CSS logical properties, and a per-element mirror policy for Arabic and Hebrew.

Right-to-left localization for Arabic and Hebrew is a document-direction decision, not a translated mirror of the left-to-right template. The interface direction, reading order, and bidirectional text runs change at the document level; the Unicode bidirectional algorithm resolves mixed runs correctly once you set dir at the root and isolate every embedded run of the other direction, including runs nested inside it; CSS logical properties let one stylesheet serve both directions. This guide gives you the bidi model, the logical-property migration, a mirror/no-mirror policy you can apply per element, and the boundary where this work hands off to typography and accessibility.

RTL is direction, not a mirror image

One right-to-left failure is especially cheap to commit: take the finished left-to-right design, translate the strings into Arabic, and apply a late stylesheet that flips text alignment. The result reads wrong to a native speaker in ways that are hard to articulate but immediate to perceive — the eye starts on the wrong side, the visual hierarchy points the wrong way, and the page feels like a photograph of the real interface rather than the interface itself.

Right-to-left is a property of the document, not a cosmetic layer on top of it. When the direction is right-to-left, the inline base direction reverses: content on each line is ordered from the right, table columns run right to left, horizontal overflow extends to the left, default text alignment moves to the right, and the inline-start and inline-end edges of every box swap sides. In horizontal text, block-level boxes and lines still stack top to bottom, because writing-mode, not direction, sets that. Any text that mixes scripts also has to resolve which run goes which way. Alignment is the smallest part of that change and the only part a naive flip actually performs.

Not everything mirrors. Navigation, breadcrumbs, progress indicators, and back-and-forward affordances reverse because their meaning is tied to reading direction. Logos, phone numbers, media playback controls, and most brand imagery do not, because their meaning is not directional — a play triangle still points the way play has always pointed, and a wordmark is a fixed graphic, not a sentence. Deciding what mirrors and what stays is a per-element policy, which is why a blanket horizontal flip is the wrong tool: it reverses the elements that should stay fixed and distorts the assets that carry no direction at all. The correct mental model is that right-to-left is a system decision made at the document level and then refined element by element.

The Unicode bidirectional algorithm and dir

The behavior that makes mixed-script text correct is the Unicode Bidirectional Algorithm, UAX #9. CSS relies on it for bidirectional rendering (CSS Writing Modes Level 3), and the practical consequence is that you do not reorder characters yourself — you declare the base direction and let the algorithm resolve the runs.

Set the base direction on the document root. Below the root, add dir to a section only on the rare occasions when its base direction needs to change for the text to display correctly. A lang declaration does not set direction, so declare both:

html
<html lang="ar" dir="rtl">
  ...
  <p>
    تواصل معنا عبر <span dir="ltr">support@example.com</span> أو زر صفحتنا.
  </p>
</html>

The W3C Internationalization article on structural markup and direction explains where dir belongs: at the document or section root, set deliberately, not sprinkled per element to patch symptoms. Where the base direction of a string is not known until runtime — user-generated names, search terms, content pulled from a database in an unknown language — dir="auto" lets the user agent infer direction from the first character with a strong directionality. The HTML specification calls this heuristic very crude and urges authors to use it only as a last resort, when the direction of the text is truly unknown and no better server-side heuristic can be applied. W3C also notes that it is not foolproof: text that begins with a strong character of the other direction is given the wrong direction.

The case that breaks naive implementations is an embedded left-to-right run inside a right-to-left paragraph: a Latin brand name, a URL, a file path, an order number. Without isolation, the bidi algorithm can pull adjacent punctuation and digits into the wrong visual position, so a sentence that is logically correct displays scrambled. The fix is bidi isolation, not manual reordering. Wrap the embedded run tightly in markup: an element with dir="ltr" when you know its direction, or <bdi> (or dir="auto" on an element that already wraps it tightly) when you do not. Either way the run is isolated and resolved as its own unit, so it cannot corrupt the surrounding text. CSS Writing Modes Level 3 advises HTML authors not to use the CSS unicode-bidi property for this, because browsers can turn off CSS styling:

html
<p dir="rtl">
  رقم الطلب <bdi>#A-10925</bdi> قيد المعالجة.
</p>

The W3C inline bidi markup article walks through when isolation is required and why markup — the dir attribute on a tightly wrapping element, or <bdi> when the direction is unknown — is preferable to Unicode control characters wherever markup is available. Where markup is not available, such as the title element and attribute values, it treats the control characters as the only option. The rule for a localization team is short: declare the base direction at the root, isolate any embedded run whose direction differs, and never reorder characters in the source to make a particular rendering look right — that source will render wrong the moment the surrounding content changes.

CSS logical properties over physical ones

A stylesheet written in physical terms — margin-left, padding-right, left, float: left — encodes the left-to-right assumption into every component. Supporting right-to-left then means a parallel stylesheet or a thicket of [dir="rtl"] overrides that drift out of sync the first time someone adds a component and forgets the mirror.

CSS logical properties solve this by expressing offsets relative to the writing direction instead of the screen. margin-inline-start is the leading edge in both directions; padding-inline sets both inline edges at once; inset-inline-start positions relative to the start of the inline axis; text-align: start aligns to the reading direction without a conditional. The MDN reference on CSS logical properties and values catalogs the full mapping from physical to logical.

css
/* Physical — encodes the left-to-right assumption */
.card { margin-left: 1rem; padding-right: 2rem; border-left: 3px solid; }

/* Logical — one rule, correct in both directions */
.card {
  margin-inline-start: 1rem;
  padding-inline-end: 2rem;
  border-inline-start: 3px solid;
}

The migration is mechanical but not optional: hardcoded left/right offsets and float-based directional layouts are the residue that survives a "we support RTL" claim and breaks in production. Flexbox and grid already follow the inline axis, so layouts built on them mostly mirror for free; the work concentrates in spacing, absolute positioning, and any component that nudges an element by a fixed pixel offset. The discipline that keeps it from regressing is a continuous-integration check that renders key components in both directions and fails on physical-property reintroduction, because the next developer will reach for margin-left out of habit and nothing in the language stops them.

Mixed content, numbers, and forms

Inside a right-to-left paragraph, several things deliberately stay left-to-right. Latin brand names, URLs, email addresses, code, and identifiers are left-to-right runs embedded in a right-to-left flow — the bidi isolation from the section above is what keeps them intact rather than visually shuffled.

Digits are the trap teams do not anticipate. Arabic locales may use Western digits or Arabic-Indic digits depending on the market — CLDR sets a different default numbering system for different Arabic locales — and the choice is a per-locale decision, not a property of the script. Treating digit shaping as automatic produces phone numbers, prices, and order references that are correct in one Arabic market and wrong in another. The numbering system is locale data, resolved from the locale rather than assumed from the language.

There is a second way to patch bidi problems that should not replace markup: inserting the invisible Unicode directional-mark characters — the left-to-right and right-to-left marks — into the source text by hand to force a particular rendering. This appears to work on the string that was tested and silently breaks the moment the surrounding content changes, because the marks are positional patches, not structural declarations, and they accumulate as invisible cruft that no one can see in an editor. The structural tools — the dir attribute and <bdi> — declare intent that survives content change; hand-inserted marks encode a snapshot that does not. If a string already contains these marks from a prior fix and the content can be marked up, re-express the intent with isolation markup rather than adding more marks. W3C still uses the Unicode control characters where markup is not available, such as the title element and attribute values, and suggests adding a right-to-left or left-to-right mark immediately after a wrapped phrase that is followed by a number or by another opposite-direction phrase, to bullet-proof the text for legacy or non-conformant browsers.

Forms invert in a way that surprises first-time implementers. Labels, help text, validation messages, and the field flow all run right-to-left, but the input direction of an individual field may still be left-to-right when its content is inherently left-to-right.

FieldField/label flowInput directionNote
Name, address (local script)RTLRTLFollows document direction
Email, URLRTLLTRContent is inherently left-to-right
Phone numberRTLLTR or RTLDecide per locale; digit shaping is locale data
Numeric amount, codeRTLLTRIsolate so it does not corrupt the line
Free text commentRTLauto`dir="auto"` infers from first strong character

The deeper depth on names, address structure, and phone formatting belongs to a different concern — the format-conventions work in this same topic owns how those values are shaped per locale. This section owns only the direction handling: which way the field and its label flow, and where an explicit left-to-right or auto direction has to be set on the input so a bidi-mixed value does not display scrambled.

Icons, media, and motion direction

Iconography splits cleanly once you ask whether the icon's meaning depends on reading direction. Directional icons — back and forward arrows, list indentation, progress and stepper chevrons, the send arrow in a composer — mirror, because their meaning is "the direction you came from" or "the direction you are going," and that reverses with the reading order. Non-directional icons — a magnifier, a gear, a trash can, a checkmark — do not mirror, because flipping them produces a backward object with no added meaning.

Media and motion follow the same test. Carousels, timelines, and horizontally paginated content reverse, because they are spatial expressions of sequence and sequence follows reading order. Brand imagery, photographs, decorative illustration, and video content do not reverse — a mirrored photograph is simply a wrong photograph. Animation that encodes progression — a drawer that slides in from the start edge, a toast that enters from the reading-start side — reverses; animation with no directional meaning, like a fade or a scale, does not.

The output of this analysis is a documented mirror/no-mirror policy: a list that says navigation mirrors, the search icon does not, the carousel reverses, the logo is fixed. That list, applied through logical properties and per-asset rules, is maintainable. A blanket transform: scaleX(-1) on a container is not — it flips the logo, reverses the photographs, and produces backward icons, then has to be unflipped case by case until the codebase is worse than if no automation had been attempted.

What this article owns and what it defers

Right-to-left work has three adjacent concerns that are easy to conflate and expensive to merge. This article owns one of them: layout direction and bidirectional text — the dir model, bidi isolation, logical properties, and the mirror policy.

Arabic typography depth — letter shaping and joining, font selection for Arabic and Hebrew, line metrics, justification behavior, and the type-scale adjustments those scripts need — is a typography concern, and the UX topic's multilingual-typography work owns it. Treating direction and type as one task produces a layout that mirrors correctly but sets the script badly, which a native reader notices as fast as a broken mirror.

Screen-reader behavior and focus order in a right-to-left interface — whether the reading order the assistive technology announces matches the visual order, and whether keyboard focus traverses the mirrored layout sensibly — is an accessibility concern, and the accessibility topic owns that depth. A right-to-left interface that is visually perfect but announces controls in source order rather than reading order is still broken for the users who most need the localization to be correct.

The practical posture is to treat the three as one coordinated right-to-left workstream with three owners: direction and bidi here, type in the UX topic's typography work, screen-reader and focus in the accessibility topic. Each takes the others as a hard dependency, and none of them is finished until all three are.

What to ship for an RTL locale

  • Set dir at the document root, and on a section only where its base direction needs to change — use dir="auto" only as a last resort for strings whose direction is truly unknown until runtime, never reorder source characters by hand
  • Isolate every embedded run of the other direction (brand names, URLs, codes, numbers), including nested runs, in markup: a tightly wrapping element with dir, or <bdi> when the direction is unknown
  • Migrate physical CSS offsets to logical properties and add a both-directions component check in continuous integration
  • Resolve digit shaping and numbering system from the locale, not the language, per Arabic market
  • Set explicit input direction on email, URL, phone, and numeric fields inside the right-to-left form flow
  • Document a per-element mirror/no-mirror policy instead of a blanket horizontal transform
  • Coordinate the type and screen-reader work with the typography and accessibility owners before calling the locale done
Project Inquiry