CSS Reference ยท Typography
The unicode-bidi property
Reference for the CSS unicode-bidi property: normal, embed, isolate, bidi-override, isolate-override and plaintext, with a live demo and usage notes.
Text in a right-to-left script such as Arabic or Hebrew is mixed with left-to-right text all the time: brand names, numbers, code. Browsers use the Unicode bidirectional algorithm to put such runs in the right order. The unicode-bidi property lets an element take part in that algorithm in a special way: open a new embedding level, isolate its content from the surroundings, or force every character into one direction.
It works together with direction. For normal content, you rarely need it, because the HTML elements <bdi> and <bdo> and the dir attribute set it for you.
.username { unicode-bidi: isolate; }
Try it
In the second line, the override forces the letters of the inner span to be laid out right to left, so the word appears reversed ("desserts"). Normally Latin letters would keep their natural left-to-right order regardless of the base direction.
Syntax
unicode-bidi: normal | embed | isolate | bidi-override | isolate-override | plaintext;
| Initial value | normal |
| Applies to | all elements, with effect mostly on inline-level boxes (and on block containers for some values) |
| Inherited | no |
| Animatable | no |
| Computed value | as specified |
Values
| Value | Description |
|---|---|
normal |
The element does not open an additional level of embedding. Its content takes part in the surrounding text's ordering. |
embed |
Opens an additional embedding level in the direction given by direction. Content is still ordered with neighbours. Mostly replaced by isolate. |
isolate |
The content is ordered on its own, and the element is treated as a single neutral character by the surrounding text. The usual choice for user-supplied snippets. |
bidi-override |
Forces all characters inside into the direction set by direction, ignoring their natural direction. |
isolate-override |
Combines isolate and bidi-override. |
plaintext |
Chooses the base direction from the first strong character of the content, ignoring direction, and isolates the content. |
Usage notes
- Use
isolatefor unknown content. If you insert a username or a product name of unknown direction into a sentence, wrap it in an isolated element so that punctuation next to it does not jump to the wrong side. - HTML does this for you.
<bdi>isolates its content and picks the direction from the first strong character.<bdo dir="rtl">overrides the direction. Prefer these elements when the direction is part of the content. bidi-overrideis a presentation hack. Do not use it to reverse strings in real content: the stored characters are unchanged, so copy and search return the original order.- Block-level use. Values such as
plaintextare useful on a block that contains user text, such as a chat message, to follow the language of each message. - Not inherited. Each element that needs special handling needs its own declaration.
- Related markup. Set
langanddiras well, so spell checking and speech tools know the language.
Browser support
Supported in every current browser, including the isolate, isolate-override and plaintext values.
Related
directionโ the base directionwriting-modeโ horizontal or vertical text:dir()โ select by direction- Lesson: Writing Modes and Logical Properties