Universal rules for right-to-left layout and bidirectional text. The
active DESIGN.md decides brand visual language; this file decides
how that language behaves when the script reads from the right or
mixes direction within a line.
Grounded in primary sources: Unicode UAX #9 revision 51 (Sept 2025)
- Unicode 17.0, CSS Logical Properties Level 1, HTML Living Standard (
dir,<bdi>), Tailwind v4.0/v4.2 changelogs, W3C alreq, Material 3 RTL guidance, Apple HIG internationalization.
Every full-page RTL artifact needs <html dir="rtl" lang="ar"> (or
the matching lang for Hebrew, Persian, Urdu). The lang attribute
drives font-stack selection, hyphenation, locale-aware speech
synthesis, and search-engine indexing — dir alone isn't enough.
Three patterns cover the common cases:
<html dir="rtl" lang="ar">. Everything inside inherits.<section dir="ltr" lang="en">…</section> (or vice versa) when an embedded block uses a different script. Code samples, English citations, foreign brand names.dir="auto" on the paragraph. The browser resolves direction from the first strong directional character in the run.Setting lang without dir is fine at the document root in a
default-LTR page — English doesn't need dir="ltr" there because
the bidi base direction is already LTR. Inside any opposite-direction
ancestor, lang does not reset the inherited base direction, so set
both lang and dir on the subtree (<section dir="ltr" lang="en">).
Setting dir without lang is rarely correct — at minimum drop the
appropriate ISO-639 tag in.
Hardcoded left / right is a bug for any layout that might render
RTL. Use logical properties on the inline axis. Use them on the block
axis when the writing-mode varies; physical otherwise.
| Logical | LTR resolves to | RTL resolves to |
|---|---|---|
margin-inline-start / padding-inline-start / inset-inline-start |
left | right |
margin-inline-end / padding-inline-end / inset-inline-end |
right | left |
border-inline-start |
border-left | border-right |
border-start-start-radius |
border-top-left-radius | border-top-right-radius |
text-align: start / text-align: end |
left / right | right / left |
inline-size / block-size |
width / height | width / height |
Browser support: core inline-axis logical properties are Baseline Widely Available (Chrome 87, Safari 14.1, Firefox 66; ≥95% global as of 2026-05).
Tailwind v4 changes the answer for new projects. v4.0 (2025-01-22)
folded inline-axis logical utilities into core (ms-*, me-*, ps-*,
pe-*, start-*, end-*). v4.2 (2026-02-18) added the block-axis
set (mbs-*, mbe-*, pbs-*, pbe-*) and renamed the inset
utilities: start-* / end-* are deprecated (still work) in favor
of inset-s-* / inset-e-*. The tailwindcss-rtl plugin is obsolete.
Don't write [dir="rtl"]: overrides for spacing on Tailwind v4.
UAX #9 rev 51 (Sept 2025) is a version stamp for Unicode 17.0. No
algorithm change; max_depth = 125 is permanently locked forward.
UAX #9 defines two distinct families of bidi formatting characters that solve different problems:
Use <bdi> in HTML; in plain text, pick the isolate that matches
what you know about the run. UAX #9 §2.7: "where available, markup
should be used instead of the explicit formatting characters."
<bdi> has been Baseline Widely Available since January 2020.
Reach for control characters only in plain-text contexts (logs,
plain-text emails, terminal output). When you do:
Don't reach for FSI as the default — it auto-detects from the first strong character, which is the wrong choice when you already know what direction the run should be.
dir="auto" on a paragraph or <bdi> lets the browser detect
direction from the first strong directional character. Best for
user-generated content where direction isn't known at author time.
Mirroring isn't universal. The rules below are unanimous across Material 3 RTL guidance and Apple HIG internationalization.
Must mirror:
<bdi dir="ltr"> (or <span dir="ltr">) so the digits don't reflow. Bare <bdi> is not enough: phone numbers and account numbers contain mostly weak / neutral characters, so first-strong direction detection is unreliable. Force LTR explicitly.Must not mirror:
Numerals are not a mirroring decision. They follow locale, not paragraph direction. Arabic-Indic digits carry bidi class AN, not EN — affects how they sit inside mixed-direction lines but does not flip them.
Single live conflict between platforms: the search icon. SF Symbols
ships an RTL magnifyingglass variant (Apple flips it). Material 3
says don't flip the magnifying glass (handle stays bottom-right).
Decide per-platform; don't synthesize a single rule.
Two RTL-coupled typography rules sit in this file because they cause
breakage at the layout level. The full Arabic / Hebrew typography
guide (font picks, harakat line-height, OpenType shaping, mixed-script
fallback chains) belongs in a future craft/arabic-hebrew-typography.md.
letter-spacing to Arabic runs. alreq treats
letter-spacing as a boundary concept, not a uniform tracking value.
Applying tracking breaks the cursive joining the script depends on.Web RTL handling does not auto-translate to mobile. Each platform has its own direction primitive. Skills that emit web-only artifacts can skim this section; it's the entry point for skills that ship to mobile (mobile-onboarding, mobile-app, etc.).
| Platform | Direction primitive | Spacing |
|---|---|---|
| iOS UIKit | semanticContentAttribute = .forceRightToLeft |
NSDirectionalEdgeInsets |
| iOS SwiftUI | .environment(\.layoutDirection, .rightToLeft) |
EdgeInsets with leading / trailing |
| Android Compose | CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl) |
PaddingValues accepts start / end |
| Flutter | Directionality(textDirection: TextDirection.rtl) |
EdgeInsetsDirectional.fromSTEB(...) |
| React Native | I18nManager.forceRTL(true) (requires native reload; no forceLTR parity, no react-native-web support) |
marginStart / marginEnd |
The rule across all platforms: prefer the directional primitive over
the absolute one. EdgeInsets.left/right in Flutter, paddingLeft /
paddingRight in Android, leading-vs-trailing in iOS — these are bugs
waiting for an Arabic deployment.
Form fields commonly mix scripts. Three rules cover most of it.
<input dir="auto"> for any field whose value's direction is uncertain (search boxes, comment fields, free-text inputs). The browser detects from the first strong directional character.<input type="email" dir="ltr">.<bdi> when displaying mixed-script content (a username inside a paragraph, a model number inside a description). Stops the surrounding direction from rearranging the embedded value. For values whose direction is fixed and weak-character-heavy (phone, IBAN, card number), use <bdi dir="ltr"> rather than bare <bdi> so first-strong detection doesn't misclassify.Mechanically lintable items can be flagged from CSS / source alone. Script-aware items need to detect Arabic / Hebrew runs in the rendered text and have legitimate exceptions (chart axes, physical icons, platform-specific placement).
Mechanically lintable:
left / right / text-align: left in new CSS — bug for any layout that may render RTL. Exceptions: chart x-axes, physical-object icons, platform-pinned UI like a status-bar clock. Lint with an allow-list rather than blanket banning.inline-s-* / inline-e-*" — wrong family. Those are size utilities. The inset rename is inset-s-* / inset-e-*.dir="rtl" without lang="ar" (or matching). Lint together; dir alone misses the font-stack and locale path.EdgeInsets.left/right in code that needs to render RTL. Use EdgeInsetsDirectional.start/end.Needs script detection (will false-positive without it):
text-justify: kashida for Arabic" — no browser implements it. CSS text-align: justify adds inter-word spacing and looks unnatural in Arabic; kashida elongation is the correct form, but it isn't shippable on the web today.letter-spacing applied to Arabic. Breaks cursive joining (alreq treats it as a boundary concept, not a uniform tracking value).HTML semantics:
unicode-bidi: isolate / plaintext / embed) for inline runs when <bdi> or a dir-bearing element does the job. Prefer semantic isolation in HTML for inline content; unicode-bidi: plaintext operates on a different surface (it changes how base direction is determined for each plaintext paragraph in a block) and should only be used when that block-level paragraph behavior is explicitly required and tested. The two are not drop-in equivalents — don't lint one as a replacement for the other.<bdi> around phone / IBAN / card numbers in an RTL paragraph. First-strong detection on weak/neutral characters is unreliable; force dir="ltr" explicitly.