--- name: hebrew-rtl-best-practices description: Implement right-to-left (RTL) layouts for Hebrew web applications. Use when user asks about RTL layout, Hebrew text direction, bidirectional (bidi) text, Hebrew CSS, "right to left", or needs to build a Hebrew web UI. Covers CSS logical properties, the :dir() pseudo-class, Tailwind RTL, React/Next.js RTL setup, icon mirroring, Hebrew typography, and font selection. Do NOT use for Arabic RTL (similar but different typography) unless user explicitly asks for shared RTL patterns, or for native mobile RTL (React Native I18nManager, SwiftUI, Android) which is out of scope. license: MIT compatibility: Works with Claude Code, Claude.ai, Cursor. No network required. --- # Hebrew RTL Best Practices ## Instructions ### Step 1: Set Up Document Direction Always start with the HTML attribute (not just CSS): ```html ``` This tells browsers, screen readers, and CSS to use RTL as the base direction. ### Step 2: Use CSS Logical Properties NEVER use physical directional properties for layout: | Physical (avoid) | Logical (use) | |-------------------|--------------| | `margin-left` | `margin-inline-start` | | `margin-right` | `margin-inline-end` | | `padding-left` | `padding-inline-start` | | `padding-right` | `padding-inline-end` | | `border-left` | `border-inline-start` | | `text-align: left` | `text-align: start` | | `text-align: right` | `text-align: end` | | `float: left` | `float: inline-start` | | `left: 10px` | `inset-inline-start: 10px` | This ensures the layout automatically mirrors in RTL mode. When you genuinely need a direction-specific rule that logical properties cannot express, prefer the `:dir()` pseudo-class over `[dir="rtl"]` attribute selectors: ```css /* Modern: matches the resolved direction, including dir="auto" and inheritance */ .chevron:dir(rtl) { transform: scaleX(-1); } /* Older approach: only matches an explicit dir attribute on/above the element */ [dir="rtl"] .chevron { transform: scaleX(-1); } ``` `:dir()` is part of Selectors Level 4 and resolves the *computed* direction, so it also works for elements whose direction comes from `dir="auto"` or from an ancestor, where an attribute selector would miss them. Browser support: Chrome and Edge shipped it in version 120 (late 2023), Firefox has supported it for years, and Safari added it in 16.4, so it is now Baseline (widely available). For older-browser support, keep an `[dir="rtl"]` fallback rule or use a logical property instead. Check current support at https://caniuse.com/css-dir-pseudo. ### Step 3: Handle Bidirectional Text When mixing Hebrew and English/numbers: ```css /* Isolate embedded LTR content */ .ltr-content { unicode-bidi: isolate; direction: ltr; } /* Mixed or unknown-direction content: each paragraph picks its own base direction */ .user-content { unicode-bidi: plaintext; } ``` Do not use `unicode-bidi: bidi-override` for mixed content. It switches off the implicit part of the bidi algorithm and lays every character out strictly in the `direction` value, so English inside an RTL override renders letter-reversed. Reserve it (or ``) for deliberately forcing a known visual order. Common bidi issues: - Phone numbers written with spaces (`050 321 4450`) or a `+972` prefix appearing scrambled: wrap in ``. A plain hyphenated `050-321-4450` already stays intact, because a single hyphen between two numbers joins them into one number run. - Punctuation at wrong end of sentence: Use `unicode-bidi: isolate` - URLs/emails in Hebrew text: Wrap in `` **Numbers and dates:** Standalone numbers and DD/MM/YYYY dates inside Hebrew text usually render fine because digits are weak-LTR, but a number that is immediately followed by a sign, currency, or a second number can flip. When a value must keep a fixed visual order, isolate it with `` or `unicode-bidi: isolate` rather than trusting the default bidi resolution. **Format the value, then isolate it.** Bidi isolation only stops a *correct* string from flipping; it does not produce the right string. Use `Intl` to format, then isolate: `Intl.NumberFormat('he-IL', { style: 'currency', currency: 'ILS' })` for shekel amounts and `Intl.DateTimeFormat('he-IL')` for dates, and wrap the output in `` (or `unicode-bidi: isolate`) if it sits inline in Hebrew prose. Do not force `dir="ltr"` on `he-IL` output: the currency string carries its own right-to-left marks (U+200F) and is laid out for an RTL context, so forcing LTR moves the ₪ to the other side of the number. The distinction: force `dir="ltr"` on raw digit strings such as phone numbers, which carry no direction marks, and only isolate Intl output, which does. Devs commonly conflate the two and apply bidi fixes to a formatting bug (or vice versa). **Hebrew dates need the calendar extension.** `Intl.DateTimeFormat('he-IL')` resolves to the Gregorian calendar (`resolvedOptions().calendar === 'gregory'`), so a Hebrew locale alone will not give you a Hebrew date. Request the calendar through the `-u-ca-` Unicode extension: `Intl.DateTimeFormat('he-IL-u-ca-hebrew')` formats 20 September 2026 as `9 בתשרי 5787`. Use it for holiday, yahrzeit, and dual-date displays, and keep the Gregorian format for anything users file with an authority. **Form inputs need `dir="auto"`.** Put `dir="auto"` on every `` and `