Letras Diferentes
Unicode research · Multilingual Text & Input Systems

Right-to-Left Web Interfaces: HTML dir, CSS Logical Properties and Isolation

Design and debug multilingual RTL web UIs using HTML dir, bdi, unicode-bidi, logical CSS properties, text inputs and accessibility-safe layout.

Technical referenceUnicode and web interoperability

Internationalizing a web interface for right-to-left languages requires more than setting text-align: right. Reading direction influences the display of mixed text, inline sequence, selection and certain controls, while layout mirroring depends on writing mode and logical CSS properties. Correct RTL engineering separates paragraph direction from visual alignment.

Use semantic direction rather than visual hacks

Set dir="rtl" on appropriate HTML elements or document regions when the content's base direction is right-to-left. The HTML directionality model connects with bidi behavior and is communicated to user agents and accessibility technologies.

Text alignment is separate: text-align:right changes alignment but does not establish the same Unicode bidi paragraph context as the direction attribute. Reversing strings or flipping every inline child with transforms is not a sound RTL localization strategy.

Prefer CSS logical properties over left/right assumptions

Properties such as margin-inline-start, padding-inline-end, border-inline-start and inset-inline-end express relative positions. They adapt to writing mode and direction more predictably than duplicating left/right offsets across locales.

Not every visual item should mirror: maps, charts, product photography, branded logos and mathematical formulas may retain their original orientation. Audit components individually and document directional behavior rather than applying a blanket horizontal transform to the entire page.

Isolate interpolated fragments

An Arabic sentence with an inserted English product name, username or URL is vulnerable to punctuation appearing in unexpected places if the fragment inherits the surrounding directional context. HTML <bdi> helps isolate directional text whose language or direction may be unknown.

The dir="auto" value can choose a direction based on relevant text content in suitable contexts. For dynamically generated labels, choose a clear containment strategy and test with Arabic, Hebrew, Latin, digits and punctuation. Do not indiscriminately inject Unicode direction controls into canonical identifiers.

Choose dir on input controls thoughtfully

Inputs for email addresses, numeric IDs, URLs and source code often benefit from left-to-right content direction even on an RTL interface. Natural-language search and prose controls may use the page's direction or dir="auto", depending on requirements.

Separate the direction of a field's text from its container layout. Right-aligned text is not necessarily right-to-left text. Form error messages and helper text can be multilingual independently of the value the user enters.

Mixed-direction punctuation needs full sentence tests

A rendered phrase combining Arabic, ABC-123, parentheses and a currency symbol can display punctuation in unintuitive positions. Test identifiers at sentence boundaries, not just as isolated text nodes, because neutral character resolution depends on context.

A shortcut such as surrounding every number with RTL marks can fix one sample but break another. Prefer semantic markup isolation, correctly set paragraph direction and minimal targeted controls when exporting to plain text where markup is not available.

Iconography and navigation require content-aware mirroring

Directional icons such as arrows for previous/next steps may need to reverse in RTL layouts, while play symbols, clocks, checkmarks and brand illustrations commonly should not. Keyboard navigation and tab order need separate review.

CSS flex-direction and DOM order are related but not identical to accessibility reading order. Avoid rearranging DOM nodes solely to match a screenshot, then accidentally making assistive technologies read a nonsensical sequence.

Bidirectional controls can be a security concern

User-provided text may contain U+202E RLO or other invisible controls that reorder display. They can be legitimate in some settings, but unexpected controls inside usernames, filenames or code reviews may be suspicious.

Do not ban entire RTL scripts to solve spoofing. Use a field-specific identifier or display policy, reveal directional controls in inspection interfaces, and isolate untrusted fragments when interpolated into surrounding prose.

Test Arabic and Hebrew with real fonts and layout

A face may cover Arabic characters but lack correct shaping of joining forms and marks. RTL layout cannot repair a missing GSUB/GPOS table. Font fallback may split a shaping run and cause detached combining marks or inconsistent metrics.

Use real sentences with diacritics, digits, embedded Latin runs and long wrapping lines. Validate focus indicators, caret movement, selection, browser zoom and line breaks at narrow viewport widths.

Maintain semantic markup through localization

Set language tags as well as direction where appropriate: lang="ar" dir="rtl" conveys distinct information. Translation may lengthen labels, change plural structure and alter number formatting. Prefer logical spacing and adaptable layout to pixel-perfect mirrored screenshots.

Include automated directionality fixtures and manual review with native speakers. The most robust RTL UI expresses content and flow semantics clearly enough that browsers can perform native text layout.

Reproducible example and limits of the measurement

The following specimen demonstrates the specific concept in a controlled source or browser context. It is not a substitute for fully exercising the target application with the appropriate language, platform input method and real user data. Distinguish textual transformations from display-only differences.

<main lang="ar" dir="rtl">
  <p>المنتج <bdi>ABC-123</bdi> متوفر.</p>
  <input type="email" dir="ltr" aria-label="Email">
</main>
<style>
  .panel { padding-inline: 1rem; margin-inline-start: 1rem; }
  .marker { inset-inline-end: 0; }
</style>
<!-- Do not reverse source strings or mirror all images. -->

Write down what is supposed to remain stable: the encoded byte stream, the Unicode scalar sequence, the selected locale, the logical reading order or just the user-facing meaning. These are different test assertions and should never be replaced by a single screenshot comparison.

Interoperability evidence matrix

LayerSpecimenInterpretation
Paragraph directiondir=rtlbidi base direction, not just alignment
Untrusted fragmentbdiisolates mixed-direction text
CSS spacingmargin-inline-startadapts to writing mode/direction
Email fielddir=ltrfield semantics may differ from page
Directional iconsprevious/next arrowsmirror by meaning, not blanket transform

Environment-specific output should be classified separately from violations of a normative Unicode algorithm or protocol. When locale or font support differs, explain the fallback explicitly rather than claiming the source text became invalid.

Validation approach and common false positives

  1. Paragraph direction: Prepare the controlled fixture dir=rtl. Record its Unicode scalar sequence and the environment, including browser or application version, selected locale and data format. The expected interpretation is: bidi base direction, not just alignment. Compare observed output with this contract rather than only its visual appearance.
  2. Untrusted fragment: Prepare the controlled fixture bdi. Record its Unicode scalar sequence and the environment, including browser or application version, selected locale and data format. The expected interpretation is: isolates mixed-direction text. Compare observed output with this contract rather than only its visual appearance.
  3. CSS spacing: Prepare the controlled fixture margin-inline-start. Record its Unicode scalar sequence and the environment, including browser or application version, selected locale and data format. The expected interpretation is: adapts to writing mode/direction. Compare observed output with this contract rather than only its visual appearance.
  4. Email field: Prepare the controlled fixture dir=ltr. Record its Unicode scalar sequence and the environment, including browser or application version, selected locale and data format. The expected interpretation is: field semantics may differ from page. Compare observed output with this contract rather than only its visual appearance.
  5. Directional icons: Prepare the controlled fixture previous/next arrows. Record its Unicode scalar sequence and the environment, including browser or application version, selected locale and data format. The expected interpretation is: mirror by meaning, not blanket transform. Compare observed output with this contract rather than only its visual appearance.

Build regression fixtures from actual user workflows as well as simple scalar vectors. Include logical text order, non-BMP symbols, mixed direction, combining sequences, and clipboard transitions as appropriate. Test both a positive path and an edge case that could falsify a simplified implementation.

Common misinterpretations

  • Use semantic direction rather than visual hacks: If the output differs, isolate whether the source data, parsing rules, locale metadata, selection behavior or rendering layer caused it. Avoid changing input text until the defect has been reproduced at a specific boundary.
  • Prefer CSS logical properties over left/right assumptions: If the output differs, isolate whether the source data, parsing rules, locale metadata, selection behavior or rendering layer caused it. Avoid changing input text until the defect has been reproduced at a specific boundary.
  • Isolate interpolated fragments: If the output differs, isolate whether the source data, parsing rules, locale metadata, selection behavior or rendering layer caused it. Avoid changing input text until the defect has been reproduced at a specific boundary.
  • Choose dir on input controls thoughtfully: If the output differs, isolate whether the source data, parsing rules, locale metadata, selection behavior or rendering layer caused it. Avoid changing input text until the defect has been reproduced at a specific boundary.
  • Mixed-direction punctuation needs full sentence tests: If the output differs, isolate whether the source data, parsing rules, locale metadata, selection behavior or rendering layer caused it. Avoid changing input text until the defect has been reproduced at a specific boundary.

A consistent technical diagnosis names the responsible layer and preserves the original specimen for an independent rerun. Content identity, typography, locale formatting and application input policy are not interchangeable.

Primary standards and API documentation

Use the normative sources below to resolve terminology and algorithmic requirements. APIs and Unicode standards may evolve: record relevant versions and be careful not to generalize a single browser's optional behavior as a universal requirement.

  • WHATWG HTML dir. Consult this standard or primary API reference for the relevant definitions, error cases, conformance details and implementation boundaries.
  • W3C RTL Styling Guide. Consult this standard or primary API reference for the relevant definitions, error cases, conformance details and implementation boundaries.
  • W3C Inline Bidi Markup. Consult this standard or primary API reference for the relevant definitions, error cases, conformance details and implementation boundaries.
  • CSS Logical Properties and Values Level 1. Consult this standard or primary API reference for the relevant definitions, error cases, conformance details and implementation boundaries.
  • Unicode Bidirectional Algorithm UAX #9. Consult this standard or primary API reference for the relevant definitions, error cases, conformance details and implementation boundaries.

Part of the Multilingual Text & Input Systems virtual silo. These published references explain adjacent concepts without creating duplicate category URLs: