CSS unicode-bidi Property
The CSS unicode-bidi property controls how bidirectional text is embedded, isolated, or overridden when a document contains both left-to-right and right-to-left writing.
It works with the direction property and the Unicode Bidirectional Algorithm to determine how text is displayed. It is particularly useful when English, Arabic, Hebrew, numbers, and punctuation appear together.
unicode-bidi Syntax
The unicode-bidi property accepts keywords that determine how an element participates in bidirectional text processing.
Basic Syntax
.example {
unicode-bidi: normal;
}
Embedding
.example {
direction: rtl;
unicode-bidi: embed;
}
Isolation
.example {
unicode-bidi: isolate;
}
Bidirectional Override
.example {
direction: rtl;
unicode-bidi: bidi-override;
}
Isolated Override
.example {
direction: rtl;
unicode-bidi: isolate-override;
}
Plaintext Direction Detection
.example {
unicode-bidi: plaintext;
}
CSS-Wide Keywords
.example {
unicode-bidi: initial;
}
.example {
unicode-bidi: inherit;
}
.example {
unicode-bidi: unset;
}
.example {
unicode-bidi: revert;
}
.example {
unicode-bidi: revert-layer;
}
Invalid Values
.example {
unicode-bidi: rtl;
}
.example {
unicode-bidi: ltr;
}
.example {
unicode-bidi: auto;
}
The values rtl and ltr belong to the direction property. The keyword auto is not a valid unicode-bidi value.
Property Values
| Value | Description |
|---|---|
normal |
Does not introduce additional embedding or isolation for an inline element. This is the initial value. |
embed |
Creates an additional embedding level for an inline element according to its specified direction. |
isolate |
Separates the element's bidirectional text processing from surrounding content. |
bidi-override |
Overrides the normal bidirectional ordering rules using the specified direction. |
isolate-override |
Combines bidirectional isolation with an explicit directional override. |
plaintext |
Determines the base direction of each bidi paragraph using its text content rather than the element's direction value. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | normal |
| Inherited | No |
| Applies to | All elements, with behavior depending on the element's formatting context |
| Computed value | As specified |
| Animation type | Not animatable |
| Percentages | Not applicable |
| Specification | CSS Writing Modes Level 3 |
Note: The unicode-bidi property does not select a language or change the characters in the document. It influences how characters are ordered for visual display.
How It Works
Browsers use the Unicode Bidirectional Algorithm to display text containing both left-to-right and right-to-left characters.
For example, English normally reads from left to right, while Arabic and Hebrew normally read from right to left. When these scripts appear together, the browser must determine how to arrange each sequence.
Step 1: Establish the Base Direction
.example {
direction: rtl;
}
The direction property establishes the base direction for the element.
Step 2: Choose Bidirectional Handling
.example {
unicode-bidi: isolate;
}
The isolate value prevents the element's text from affecting the bidirectional ordering of surrounding text.
Step 3: Combine the Properties
.example {
direction: rtl;
unicode-bidi: isolate;
}
Step 4: Apply the Style to Mixed Text
<p>Order number: <span class="example">مرحبا 123</span> confirmed.</p>
Understanding the Result
The Arabic text is processed as an isolated right-to-left sequence. Its characters do not influence the bidirectional ordering of the surrounding English sentence.
Important Distinction
Bidirectional text processing is different from text alignment. The text-align property controls alignment, while direction and unicode-bidi affect text direction and ordering.
The normal Value
The normal value uses the standard bidirectional processing behavior without introducing additional embedding or isolation for an inline element.
Syntax
.example {
unicode-bidi: normal;
}
Example
<p>English text <span class="example">مرحبا</span> continues here.</p>
How It Behaves
The browser applies the normal Unicode Bidirectional Algorithm to the text and surrounding content.
When to Use It
Use normal when no additional directional isolation, embedding, or override is required.
For most ordinary text, the browser's default bidirectional handling is sufficient.
The embed Value
The embed value creates an additional bidirectional embedding level for inline content.
Syntax
.example {
direction: rtl;
unicode-bidi: embed;
}
HTML Example
<p>English text <span class="embedded">مرحبا بالعالم</span> continues here.</p>
CSS Example
.embedded {
direction: rtl;
unicode-bidi: embed;
}
How It Behaves
The browser establishes a new embedding level using the element's direction. Text inside that level continues to follow the Unicode Bidirectional Algorithm.
embed vs. isolate
The embed value establishes a directional embedding but does not isolate the content from surrounding bidirectional text.
The isolate value is generally more suitable for independently supplied text, such as user names or labels.
The isolate Value
The isolate value treats an element's content as an independent bidirectional sequence when determining the ordering of surrounding text.
Syntax
.example {
unicode-bidi: isolate;
}
Right-to-Left Isolation
.example {
direction: rtl;
unicode-bidi: isolate;
}
HTML Example
<p>Message from <span class="username">مرحبا</span> received.</p>
CSS Example
.username {
direction: rtl;
unicode-bidi: isolate;
}
How It Behaves
The isolated content is processed separately, preventing its internal directional characters from changing the ordering of surrounding text.
When to Use It
Isolation is useful for user names, comments, dynamically inserted labels, and other content whose language or direction may differ from the surrounding document.
HTML Alternative
<p>Message from <bdi>مرحبا</bdi> received.</p>
The HTML <bdi> element provides semantic bidirectional isolation and is often preferable when the content itself requires isolation.
The bidi-override Value
The bidi-override value overrides the normal directional ordering rules and forces characters to follow the specified direction.
Right-to-Left Override
.example {
direction: rtl;
unicode-bidi: bidi-override;
}
Left-to-Right Override
.example {
direction: ltr;
unicode-bidi: bidi-override;
}
HTML Example
<p class="override">ABC 123</p>
CSS Example
.override {
direction: rtl;
unicode-bidi: bidi-override;
}
How It Behaves
Instead of allowing each character's inherent direction to determine its ordering, the browser applies the specified directional override.
When to Use It
Use this value only when character ordering must be deliberately overridden. It is rarely appropriate for ordinary multilingual text.
Important Consideration
A directional override can make text difficult to read or interpret. Avoid using it simply to align text or support a right-to-left language.
The isolate-override Value
The isolate-override value combines bidirectional isolation with an explicit directional override.
Syntax
.example {
direction: rtl;
unicode-bidi: isolate-override;
}
HTML Example
<p>Code: <span class="isolated-override">ABC123</span> complete.</p>
CSS Example
.isolated-override {
direction: rtl;
unicode-bidi: isolate-override;
}
How It Behaves
The content is isolated from surrounding bidirectional processing, and its internal ordering is overridden according to the specified direction.
Comparison With isolate
The isolate value preserves normal bidirectional processing within the isolated content. The isolate-override value forces the internal ordering.
When to Use It
This value is intended for specialized cases that require both isolation and forced ordering. It should not be used as a general replacement for isolate.
The plaintext Value
The plaintext value determines the base direction of each bidi paragraph from its text content rather than using the element's specified direction value.
Syntax
.example {
unicode-bidi: plaintext;
}
HTML Example
<div class="messages">
<div class="message">Hello, welcome!</div>
<div class="message">مرحبا بالعالم</div>
<div class="message">שלום עולם</div>
</div>
CSS Example
.message {
unicode-bidi: plaintext;
}
How It Behaves
The browser uses the Unicode Bidirectional Algorithm's first-strong-character method to determine the base direction of each paragraph.
Mixed-Language Content
This can be useful when displaying text supplied by users whose writing direction is not known in advance.
Important Consideration
The plaintext value does not change the actual text, and it does not automatically identify the language.
HTML Alternative
<p dir="auto">مرحبا بالعالم</p>
For ordinary HTML content, the dir="auto" attribute is often the better choice because it provides direction information through HTML semantics.
Working With direction
The unicode-bidi and direction properties serve different but related purposes.
| Property | Purpose |
|---|---|
direction |
Establishes the base text direction as left-to-right or right-to-left. |
unicode-bidi |
Controls embedding, isolation, and overriding within bidirectional text processing. |
Left-to-Right Direction
.example {
direction: ltr;
unicode-bidi: isolate;
}
Right-to-Left Direction
.example {
direction: rtl;
unicode-bidi: isolate;
}
Directional Override
.example {
direction: rtl;
unicode-bidi: bidi-override;
}
Important Consideration
Changing direction alone does not force every character to follow that direction. The Unicode Bidirectional Algorithm continues to account for the inherent direction of individual characters.
HTML Direction Attributes
HTML provides direction attributes and elements that should generally be preferred when text direction is part of the content's meaning.
The dir Attribute
<p dir="rtl">مرحبا بالعالم</p>
The dir attribute establishes the direction of the element's text.
Automatic Direction
<p dir="auto">مرحبا بالعالم</p>
The browser determines the direction from the content.
The bdi Element
<p>User: <bdi>مرحبا</bdi></p>
The <bdi> element isolates text whose direction may differ from surrounding content.
The bdo Element
<bdo dir="rtl">ABC123</bdo>
The <bdo> element explicitly overrides text direction.
Choosing HTML or CSS
Use HTML when direction is an inherent characteristic of the content. Use CSS for presentation-specific bidirectional behavior when appropriate.
For user-generated content, HTML direction attributes and isolation elements usually provide clearer semantics than applying directional overrides through CSS.
Related CSS Properties
direction
.example {
direction: rtl;
}
Controls the base direction of text and certain layout behaviors.
text-align
.example {
text-align: start;
}
Aligns text within its containing block without changing character ordering.
writing-mode
.example {
writing-mode: vertical-rl;
}
Controls whether text is arranged horizontally or vertically.
text-orientation
.example {
text-orientation: mixed;
}
Controls the orientation of characters in vertical writing modes.
Complete Example
.message {
direction: rtl;
unicode-bidi: isolate;
text-align: start;
}
This example establishes right-to-left direction, isolates the content, and aligns it to the logical start edge.
Inheritance
The unicode-bidi property is not inherited. Child elements do not automatically receive their parent's declared value.
Parent Element
.parent {
unicode-bidi: isolate;
}
Child Element
.child {
unicode-bidi: normal;
}
The child uses its own computed value, although it still participates in the bidirectional context established by its ancestors.
Explicit Inheritance
.child {
unicode-bidi: inherit;
}
Restore the Initial Value
.child {
unicode-bidi: initial;
}
This restores the initial value of normal.
Using unset
.child {
unicode-bidi: unset;
}
Because the property is not inherited, unset restores its initial value.
Comparison With direction
Unlike unicode-bidi, the direction property is inherited. Keep this difference in mind when styling nested elements.
Practical Examples
Isolate a User Name
.username {
unicode-bidi: isolate;
}
Isolate Right-to-Left Text
.rtl-text {
direction: rtl;
unicode-bidi: isolate;
}
Display Unknown Text Direction
.user-message {
unicode-bidi: plaintext;
}
Create a Directional Embedding
.embedded-text {
direction: rtl;
unicode-bidi: embed;
}
Force Directional Ordering
.override-text {
direction: rtl;
unicode-bidi: bidi-override;
}
Isolated Directional Override
.isolated-override {
direction: rtl;
unicode-bidi: isolate-override;
}
Mixed-Language Notification
<p>Message from <bdi>مرحبا</bdi> received.</p>
In this example, the HTML <bdi> element is a suitable alternative to a CSS isolation rule.
unicode-bidi Example
This example demonstrates normal bidirectional text, isolated text, and a directional override. The Arabic text means "Hello" and is displayed alongside English text.
HTML Example
<div class="bidi-demo">
<div class="bidi-row">
<strong>normal</strong>
<p>Message: <span class="bidi-normal">مرحبا</span> received.</p>
</div>
<div class="bidi-row">
<strong>isolate</strong>
<p>Message: <span class="bidi-isolate">مرحبا</span> received.</p>
</div>
<div class="bidi-row">
<strong>bidi-override</strong>
<p><span class="bidi-override">ABC123</span></p>
</div>
</div>
CSS Example
.bidi-demo {
display: grid;
gap: 12px;
}
.bidi-row {
padding: 12px;
border: 1px solid #d1d5db;
border-radius: 4px;
}
.bidi-row strong {
display: block;
margin-bottom: 6px;
}
.bidi-row p {
margin: 0;
}
.bidi-normal {
direction: rtl;
unicode-bidi: normal;
}
.bidi-isolate {
direction: rtl;
unicode-bidi: isolate;
}
.bidi-override {
direction: rtl;
unicode-bidi: bidi-override;
}
Message: مرحبا received.
Message: مرحبا received.
ABC123
Understanding the Results
The first example uses normal bidirectional processing. The second isolates the Arabic text from the surrounding English sentence. The third forces the Latin characters to follow right-to-left ordering.
normal
The browser determines the display order using the standard Unicode Bidirectional Algorithm.
isolate
The Arabic text is treated as an independent bidirectional sequence, preventing it from influencing the ordering of surrounding text.
bidi-override
The browser overrides the normal directional behavior of the Latin characters.
Experiment With plaintext
.bidi-isolate {
unicode-bidi: plaintext;
}
The browser determines the base direction from the content instead of using the element's specified direction.
Experiment With Left-to-Right Override
.bidi-override {
direction: ltr;
unicode-bidi: bidi-override;
}
The override now forces left-to-right ordering.
Accessibility Considerations
Correct bidirectional text handling helps multilingual content remain readable and understandable.
Prefer Semantic HTML
Use the HTML dir attribute and appropriate elements such as <bdi> when direction is part of the content's meaning.
Avoid Unnecessary Overrides
Directional overrides can produce unexpected character ordering and make text difficult to interpret.
Isolate User-Generated Content
Content supplied by users may contain text with an unknown writing direction. Isolation helps prevent it from changing the order of surrounding punctuation and text.
Preserve Logical Source Order
Keep text in its natural logical order in the HTML source. Do not manually reverse characters to create right-to-left presentation.
Identify Languages Correctly
<p lang="ar" dir="rtl">مرحبا بالعالم</p>
The lang attribute identifies the language, while dir establishes text direction.
Test Assistive Technology
Verify that mixed-language content is understandable with screen readers and other assistive technologies.
Avoid Visual-Only Direction Changes
CSS directional overrides do not change the logical order of characters in the document source. Do not rely on visual reordering to communicate meaning.
Common Mistakes
Using rtl as a unicode-bidi Value
.example {
unicode-bidi: rtl;
}
Use direction: rtl to specify right-to-left direction.
Using auto as a unicode-bidi Value
.example {
unicode-bidi: auto;
}
The auto value is available for the HTML dir attribute, not the CSS unicode-bidi property.
Confusing Text Alignment With Direction
.example {
text-align: right;
}
Text alignment does not establish bidirectional isolation or override character ordering.
Using bidi-override for Ordinary RTL Text
Most Arabic and Hebrew content does not require a directional override. Use semantic direction settings and normal bidirectional processing.
Assuming unicode-bidi Is Inherited
The property is not inherited. Child elements use their own computed values.
Ignoring Mixed-Language Punctuation
Punctuation and numbers can appear in unexpected positions when mixed-direction text is not isolated appropriately.
Manually Reversing Characters
Do not reverse text in the HTML source to simulate right-to-left display.
Using CSS Instead of Appropriate HTML
When text direction is a property of the content itself, HTML direction attributes and elements are generally preferable.
Important Considerations
Keep the following points in mind when using unicode-bidi:
- The property controls aspects of bidirectional text processing.
- It works with the Unicode Bidirectional Algorithm.
- The initial value is
normal. - The property is not inherited.
- It is not animatable.
- The
normalvalue uses standard bidirectional processing. - The
embedvalue creates an additional embedding level. - The
isolatevalue separates content from surrounding bidirectional processing. - The
bidi-overridevalue forces directional ordering. - The
isolate-overridevalue combines isolation and overriding. - The
plaintextvalue determines paragraph direction from content. - The
directionproperty establishes base text direction. - The
directionproperty is inherited, unlikeunicode-bidi. - The property does not identify the language of the text.
- The property does not change characters in the HTML source.
- Bidirectional ordering is different from text alignment.
- HTML
dirattributes are generally preferred for semantic direction. - The HTML
<bdi>element provides bidirectional isolation. - The HTML
<bdo>element provides explicit directional overriding. - Use isolation for independently supplied mixed-direction content.
- Avoid unnecessary directional overrides.
- Preserve the natural logical order of source text.
- Test punctuation, numbers, and nested text in multilingual interfaces.
- Verify accessibility with assistive technologies.
Browser Support
The CSS unicode-bidi property is widely supported across modern browsers. The established values normal, embed, and bidi-override have long-standing support.
The newer isolation-related values, including isolate, isolate-override, and plaintext, should be checked when supporting older browser versions.
For current compatibility information, visit Can I Use? and search for unicode-bidi.
Basic Declaration
.example {
unicode-bidi: isolate;
}
Directional Override
.example {
direction: rtl;
unicode-bidi: bidi-override;
}
Feature Detection
@supports (unicode-bidi: isolate) {
.example {
unicode-bidi: isolate;
}
}
HTML Alternative
<bdi>مرحبا</bdi>
For content that requires semantic bidirectional isolation, the HTML <bdi> element is often the preferred approach.
Testing Recommendations
Test mixed-direction text containing Latin, Arabic, or Hebrew characters along with punctuation and numbers. Check both visual ordering and accessibility.
Specifications
The unicode-bidi property is defined in the CSS Writing Modes specification.
CSS Writing Modes Level 3 - The unicode-bidi Property
The specification describes how CSS controls bidirectional embedding, isolation, and overriding in relation to the Unicode Bidirectional Algorithm.
For additional documentation and examples, consult MDN Web Docs.
