👀 Live Preview
Arabic product name isolated inside English text:
The product قهوة رائعة means “Great Coffee” in Arabic.

By the end of this tutorial, you’ll confidently isolate bidirectional text in multilingual and user-generated content.
Wrap mixed-direction text in <bdi> for automatic isolation.
Know when to isolate vs explicitly override text direction.
Protect usernames, IDs, and product names from direction spillover.
Embed Arabic and Hebrew safely inside English paragraphs.
Pair lang hints with isolation for screen readers.
Ship bdi markup with confidence in modern browsers.
<bdi> Tag?The bidirectional isolation element (<bdi>) represents a span of text that is directionally isolated from its neighbors. The browser’s Unicode bidirectional algorithm treats content inside <bdi> as a separate embedding.
bdi stands for Bidirectional Isolation. RTL text inside cannot reorder adjacent LTR punctuation, numbers, or words outside the element—essential for usernames and dynamic data.
Common uses include usernames, product names, IDs, and mixed-language quotes in predominantly LTR or RTL pages. Direction is auto-detected; no dir attribute is required on the tag itself.
Wrap text that may have a different direction inside <bdi> tags:
<bdi>Your Isolated Text Here</bdi><bdi> is an inline element—it nests inside paragraphs, lists, and tables.<bdi />) is not valid in HTML.lang when the isolated language is known (e.g. lang="ar").| Use Case | Code Snippet | Result |
|---|---|---|
| Basic isolation | <bdi>قهوة</bdi> | قهوة |
| With lang hint | <bdi lang="ar">مرحبا</bdi> | مرحبا |
| Username in sentence | User <bdi>إيان</bdi> commented | User إيان commented |
| vs bdo override | <bdo dir="rtl">...</bdo> | Forces explicit direction |
| Tag-specific attrs | None | Global attributes only |
| Full RTL page | <html dir="rtl"> | Page-level direction |
<bdi> vs <bdo>Both handle bidirectional text, but they solve different problems:
| Element | Behavior | Best for |
|---|---|---|
<bdi> | Isolate; auto direction | Dynamic or unknown text (usernames, comments) |
<bdo> | Override with dir | Known RTL/LTR when you must force display order |
dir attribute | Set on any element | When direction is known in advance |
| Page-level | <html dir="rtl"> | Fully right-to-left documents |
<!-- Unknown username: isolate with bdi -->
<p>User <bdi>إيان</bdi> commented.</p>
<!-- Known override: force direction with bdo -->
<p><bdo dir="rtl">This text displays right-to-left.</bdo></p>The <bdi> tag has no tag-specific attributes. Isolation behavior is built in. Apply global attributes for styling and language hints:
class / id GlobalHook for CSS selectors and JavaScript targeting.
<bdi class="rtl-text">lang A11yHints the language of isolated text for screen readers and typography.
lang="ar"dir OptionalUsually unnecessary—isolation auto-detects direction. Use when you need an explicit hint.
dir="auto"<bdi class="rtl-text" lang="ar">مرحبا</bdi>Three bidirectional isolation patterns with copy-ready code, live previews, and hands-on practice.
Arabic product name isolated inside English text:
The product قهوة رائعة means “Great Coffee” in Arabic.
Wrap RTL text in an LTR paragraph to prevent direction spillover.
<p>
In this example, the product name
<bdi>قهوة رائعة</bdi> means "Great Coffee" in Arabic.
</p>Here are the most frequent ways developers use the <bdi> tag.
Combine <bdi> with a CSS class for isolated RTL text that also has custom styling.
<p>Hello, <bdi class="rtl-text">مرحبا</bdi> world!</p>Wrap unpredictable usernames or IDs in <bdi> so mixed scripts and numbers display correctly in lists and comments.
<ul>
<li>User <bdi>إيان</bdi> rated this 5 stars</li>
<li>User <bdi>user_483</bdi> left a review</li>
<li>User <bdi>שלום123</bdi> posted yesterday</li>
</ul>Proper bidirectional handling improves readability for all users:
<bdi>lang="ar" or lang="he" when the language is knowndir="rtl" on <html> for fully RTL pagesPlace usernames, product names, or foreign phrases inside <bdi>.
The Unicode bidirectional algorithm runs separately inside the bdi boundary.
LTR punctuation, numbers, and words outside bdi are not reordered by RTL content inside.
Readers see Arabic, Hebrew, or mixed usernames in the right order without breaking the surrounding sentence.
The <bdi> tag is supported in all modern browsers. Internet Explorer 11 and below may have limited bidirectional isolation behavior.
From IE 11 to the latest mobile browsers — bidirectional isolation is a core HTML5 internationalization feature.
Bottom line: Ship bidirectional isolation markup with confidence. Use <bdi> for dynamic mixed-language content in every production environment today.
The <bdi> tag is a small but important tool for multilingual and user-generated content. Use it to isolate text with uncertain direction, pair it with lang when known, and reach for <bdo> only when you need to explicitly override direction.
<bdi>lang when the isolated language is knowndir on <html> for fully RTL pages<bdi>—use dir on block elements instead<bdi> when <bdo dir> is the clearer choice<meta charset="UTF-8">) for non-Latin scripts<bdi>Bookmark these before you ship — they’ll keep mixed-language UI readable and accessible.
<bdi> = Bidirectional Isolation—separate embedding for the Unicode algorithm.
RTL text cannot reorder surrounding LTR punctuation, numbers, or words.
BehaviorIdeal for usernames, product names, IDs, and user-generated text.
Patterns<bdo> overrides direction; <bdi> isolates it automatically.
No tag-specific attributes—use global class and lang.
Supported in all modern browsers; IE 11+ with limited older behavior.
Compatibility<bdi> isolates and auto-detects direction. <bdo> requires dir="ltr" or dir="rtl" to explicitly override display direction.<bdi> for unknown or user-generated text. Use dir on elements when you know the text direction in advance.class, id, and lang.Open the Try It editor and test Arabic product names and mixed usernames with bdi.
7 people found this page helpful