← Hub · Open the note

RTL + mixed-direction text — demo — BEFORE/AFTER

Try flipping page direction. The “BEFORE” card uses physical CSS + missing language/direction hints; the “AFTER” card uses lang, dir, <bdi>, and logical CSS.

Toggles the document direction between left-to-right and right-to-left.
BEFORENo lang/dir hints + physical CSS (breaks in RTL)

Issues: screen readers may mispronounce foreign-language text; mixed-direction strings can reorder punctuation; “start” styling stays on the physical left even in RTL.

Shipping note: مرحبا بك في مكتبنا (Office A‑12).

No lang or dir on the Arabic phrase.

Receipt: User: أحمد — Order #12345 (Paid).

No isolation for user-generated RTL names (try RTL mode).

Visual “start” marker: this border + padding stay on the left even when the page is RTL.

Try: click Page dir to switch to RTL. Notice the “start marker” is still on the left.

AFTERInline lang/dir + <bdi> + logical CSS

Pattern: set the document’s primary language once; add inline lang (and dir when needed) for foreign-language runs; wrap user content in <bdi>; use logical CSS properties (e.g. border-inline-start).

Shipping note: مرحبا بك في مكتبنا (Office A‑12).

Arabic phrase is explicitly labeled: lang="ar" dir="rtl".

Receipt: User: أحمد — Order #12345 (Paid).

User-generated name is isolated with <bdi>.

Visual “start” marker: this border + padding follow the writing direction (LTR vs RTL).

Uses border-inline-start + padding-inline-start.

Tiny snippet you can copy

<p>User: <bdi>{{displayName}}</bdi> — Order #12345</p>

<p>
  <span lang="ar" dir="rtl">مرحبا بك في مكتبنا</span>
  (Office A‑12)
</p>

Notes

Why this matters
Correct language/direction metadata helps screen readers choose pronunciation rules and helps the bidi algorithm avoid confusing punctuation/number ordering.
What this demo is
A small, static illustration. It’s not a complete internationalization (i18n) guide.
Next
Read the note for a checklist and when to use dir="auto".