HTML: bdo, bdi (bidirectional text)

By Xah Lee. Date: .

Explain HTML tags bdo and bdi

Explain HTML tags bdo and bdi

ai answer

<bdo> and <bdi> are HTML elements used for handling bidirectional (BiDi) text—text that mixes left-to-right (LTR) languages (like English) with right-to-left (RTL) languages (like Arabic or Hebrew).

<bdo> — Bidirectional Override

The <bdo> element (Bidirectional Override) forces the text inside it to be rendered in a specific direction, overriding the browser’s normal bidirectional algorithm.

Example:

<p>This text goes left to right.</p>
<p><bdo dir="rtl">This text will go right to left.</bdo></p>

Key points:

<bdi> — Bidirectional Isolation

The <bdi> element (Bidirectional Isolation), introduced in HTML5, tells the browser to treat the text inside it in isolation from the surrounding text.

It is especially useful when:

How isolation works:

  1. The direction of the text inside <bdi> does not affect the surrounding text.
  2. The direction of the surrounding text does not affect the text inside <bdi>.

Example (common use case with usernames of unknown direction):

<ul>
  <li>User <bdi>hrefs</bdi>: 60 points</li>
  <li>User <bdi>jdoe</bdi>: 80 points</li>
  <li>User <bdi>إيان</bdi>: 90 points</li>
</ul>

Without <bdi>, an Arabic name can mess up the punctuation and numbers around it (e.g., the colon and score can appear in the wrong place).

Key Differences

Feature <bdo> <bdi>
Purpose Override direction Isolate direction
Required attribute dir (ltr or rtl) None (optional dir)
Introduced HTML 4 HTML5
Best for Forcing a specific direction Unknown or mixed direction content
Affects surrounding text Yes (can cause problems) No
Recommendation Use sparingly Preferred for dynamic content

Practical Advice

Both elements are inline and support global attributes.