๐ What is unicode-bidi?
The unicode-bidi property controls how the browser handlesbidirectional (BiDi) text โ text that mixes left-to-right (LTR) and right-to-left (RTL) scripts in the same line, such as English + Arabic.
Note
โ Useful for multilingual UIs and data fields
โ Advanced property โ used only when the normal behavior breaks
๐ฏ Why Use unicode-bidi?
- Fix messy ordering in mixed LTR + RTL text
- Force text to behave in a specific direction
- Protect sensitive content like codes, IDs, numbers
- Control embedding and isolation of directional contexts
๐ Syntax
unicode-bidi Syntax
unicode-bidi: normal | embed | isolate | bidi-override | isolate-override | plaintext;๐ Values Explained
| Value | Meaning |
|---|---|
| normal | Uses the browserโs default bidirectional algorithm |
| embed | Creates a nested directional context based on direction |
| isolate | Isolates the text so its direction doesnโt affect siblings |
| bidi-override | Forces characters to follow direction strictly, ignoring natural script direction |
| isolate-override | Combination of isolate + override |
| plaintext | Each separate segment follows its own script direction โ no merging |
Note
๐งช Example 1 โ Mixed Text Rendering Problem
Consider English mixed with Arabic without control:
HTML
<p>Hello ุงูุณูุงู
ุนุงูู
</p>The browser may reorder punctuation or numbers unexpectedly.
๐งช Example 2 โ Using embed
embed Example
.embed {
direction: rtl;
unicode-bidi: embed;
}HTML
<p class="embed">Hello 123 ุนุงูู
</p>Creates a consistent nested RTL context inside the element.
๐งช Example 3 โ Using bidi-override
Override Example
.override {
direction: rtl;
unicode-bidi: bidi-override;
}HTML
<p class="override">Hello123</p>This forces characters to be displayed strictly in RTL order (even English letters are reversed).
๐งช Example 4 โ Using isolate
isolate Example
.isolated {
unicode-bidi: isolate;
}HTML
<div>Arabic: ู
ุฑุญุจุง <span class="isolated">123-ABC</span></div>The isolated span prevents the numbers from affecting surrounding Arabic text.
๐งช Example 5 โ isolate-override
isolate-override Example
.iso-override {
direction: rtl;
unicode-bidi: isolate-override;
}HTML
<p class="iso-override">CSS12345</p>Text is isolated AND forced to follow RTL strictly.
๐งช Example 6 โ plaintext
plaintext Example
.plain {
unicode-bidi: plaintext;
}HTML
<p class="plain">Hello ุนุงูู
123</p>Each script (English, Arabic, numbers) retains its own direction โ no merging.
๐ง When Should You Use unicode-bidi?
- When mixed RTL/LTR text renders incorrectly
- When UI fields must preserve input order (IDs, codes, passwords)
- When embedding isolated RTL text inside LTR context
- When writing bilingual interfaces
- When correcting misbehavior of numbers in RTL layout
โ ๏ธ Common Mistakes
- โ Using unicode-bidi alone without setting direction
- โ Applying bidi-override unnecessarily (reverses text!)
- โ Assuming plaintext works like isolate (it behaves differently)
- โ Overusing BiDi controls โ makes layout harder to maintain
Note
๐ฅ Summary
unicode-bidi is a powerful property used to take fine-grained control of how bilingual or bidirectional text is displayed. When the natural Unicode BiDi algorithm fails or becomes unpredictable, unicode-bidi ensures your text flows exactly how you intend.
Learn more โMDN Docs ๐