Skip to content
Tutorials Center
My learning

Topics

HTML Reference ยท Inline Text

The <bdi> element

Reference for the HTML <bdi> element: isolating text of unknown direction, such as user names, so it does not scramble the surrounding sentence.

The <bdi> element (bidirectional isolate) wraps text whose writing direction you don't know in advance, typically something inserted from a database or typed by a user. The browser works out the direction of the text inside on its own and keeps it from affecting the text around it.

This matters when right-to-left text (Arabic, Hebrew, Persian) and left-to-right text share a line. Without isolation, a right-to-left name followed by a number or punctuation can make the browser reorder the neighbouring characters in confusing ways.

HTML
<li>User <bdi>{{ name }}</bdi>: 42 posts</li>

Try it

With and without isolation

In the first list, the Arabic name pulls the colon and the number into its right-to-left run, so "9" moves to the wrong side. Inside <bdi>, the name is isolated and the rest of the line reads normally.

Attributes

This element has no attributes of its own. It accepts the global attributes. Its dir attribute behaves differently from other elements: when dir is missing, <bdi> acts as if it had dir="auto" rather than inheriting the parent's direction.

Usage notes

  • Use it around inserted text. Usernames, product names, search terms, comments: anything whose language your template does not control is a good candidate.
  • <bdi> vs dir="auto". You can get the same isolation by adding dir="auto" to a <span>. <bdi> saves you remembering the attribute and makes the intent clear.
  • <bdi> vs <bdo>. <bdo> forces a direction and reorders the characters. <bdi> only isolates and lets the browser detect the right direction.
  • Know the page direction too. Isolating fragments helps, but the page itself still needs the correct dir and lang on <html>.

Technical summary

Content categories Flow content, phrasing content, palpable content
Permitted content Phrasing content
Tag omission None; both the start and end tags are required
Permitted parents Any element that accepts phrasing content
Implicit ARIA role generic
DOM interface HTMLElement
Default display inline (with unicode-bidi: isolate)

Browser support

Supported in all current browsers.