HTML <bdi> Tag

Beginner
6 min read
Updated: Oct 2026
4 examples
Live preview

Definition and Usage

The <bdi> element (Bidirectional Isolate) tells the browser’s bidirectional algorithm to treat its contents separately from surrounding text. Direction inside does not spill out, and surrounding direction does not force the isolated span.

Use it for usernames, titles, or other dynamic text whose direction you may not know (LTR Latin, RTL Arabic/Hebrew, or mixed). Prefer <bdo> only when you must force dir to ltr or rtl.

Baseline · Widely available.

Not deprecated. Stable across major browsers since about January 2020.

Default direction.

If you omit dir, <bdi> still behaves as if dir="auto" were set — direction is inferred from the text.

HTML Syntax

syntax.html
<bdi> text</bdi>

Both start and end tags are required. Content is phrasing content. Optional dir="ltr", rtl, or auto (auto is the effective default).

Attributes

<bdi> has no element-specific attributes. It uses global attributes; these matter most:

AttributeDescriptionTry it
(isolation built in)No tag-only attributes — wrapping in <bdi> is enough for auto isolationTry it
dirOptional. Omit for auto. Or set ltr / rtl / auto explicitlyTry it
class / langStyle hooks and language of the isolated spanTry it

Global Attributes

The <bdi> tag also supports the Global Attributes in HTML.

Live Preview

Compare a plain <span> with <bdi> around an RTL name next to LTR ranking text.

Watch how “ - 1st place” stays readable when the name is isolated.

Ranking line

اَلأَعْشَى - 1st place

Using <span> — neutral characters may follow the RTL name.

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Problem Without Isolation

An RTL name inside an LTR line can scramble neutral characters like - and digits.

HTML
<ul>
  <li><span>اَلأَعْشَى</span> - 1st place</li>
  <li><span>Jerry Cruncher</span> - 2nd place</li>
</ul>
Try It Yourself

How It Works

  1. Keep fixed English text such as - 1st place.
  2. Insert an RTL name with a plain <span>.
  3. Neutral characters (spaces, dashes, some digits) can take on the RTL direction.
  4. Result: the ranking line can look garbled next to the Arabic name.

Example 2 — Fix with <bdi>

Wrap the unknown or RTL name so surrounding LTR text stays stable.

HTML
<ul>
  <li><bdi>اَلأَعْشَى</bdi> - 1st place</li>
  <li><bdi>Jerry Cruncher</bdi> - 2nd place</li>
</ul>
Try It Yourself

How It Works

  1. Wrap each name in <bdi>…</bdi>.
  2. Leave the ranking text outside the isolate.
  3. Browser isolates direction so - 1st place stays LTR.
  4. Works for LTR names too — safe default for dynamic lists.

Example 3 — Mixed Names in One List

Isolate every dynamic name when direction may vary per item.

HTML
<h1>World wrestling championships</h1>
<ul>
  <li><bdi>Evil Steven</bdi>: 1st place</li>
  <li><bdi>François fatale</bdi>: 2nd place</li>
  <li><bdi>الرجل القوي إيان</bdi>: 3rd place</li>
</ul>
Try It Yourself

How It Works

  1. Treat each name as unknown direction data.
  2. Wrap every name in <bdi> for a consistent pattern.
  3. Keep labels like “1st place” outside the isolate.
  4. Optional class can style names without changing bidi behavior.

Example 4 — bdi vs bdo

Isolate with auto direction, or force a direction when you already know it.

HTML
<p>
  User:
  <bdi>مسافر</bdi>
  (isolated, auto direction)
</p>
<p>
  Forced LTR display:
  <bdo dir="ltr">مسافر</bdo>
</p>
Try It Yourself

How It Works

  1. Use <bdi> when direction is unknown or should follow the content.
  2. Use <bdo dir="…"> when you must override direction.
  3. bdo requires dir (ltr or rtl).
  4. Prefer semantic HTML over CSS unicode-bidi: isolate for the same job.

Edge Cases & Pitfalls

Most bidi bugs show up next to punctuation, numbers, and user-generated names.

dynamic

Isolate unknown direction text

Usernames and CMS titles are classic <bdi> cases — you often cannot hard-code dir.

wrap

Wrap only the variable part

Keep fixed labels like “1st place” outside <bdi> so they stay in the page language direction.

css

Prefer <bdi> over CSS isolate

unicode-bidi: isolate is not semantic; browsers may ignore presentational CSS for this.

bdo

Do not confuse with <bdo>

<bdo> forces direction. Use it when you know ltr/rtl, not for auto isolation.

dir

dir="auto" is already implied

Omitting dir on <bdi> still isolates with automatic direction detection.

Browser Support

The <bdi> element is core HTML phrasing content for bidirectional isolation. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

<bdi>

Widely available since about January 2020. Chrome, Firefox, Safari, Edge, and Opera isolate bidirectional text. Always test with real RTL samples in your layout.

95% Global support (approx.)
Google Chrome Yes
Full support
Mozilla Firefox Yes
Full support
Apple Safari Yes
Full support
Microsoft Edge Yes
Full support
Opera Yes
Full support
Samsung Internet Yes
Full support
Internet Explorer No
Not supported
<bdi> Widely supported

Bottom line: Safe for modern sites that mix LTR and RTL user content. Provide sensible fallbacks only if you must support very old browsers.

Key Takeaways

  • Role: <bdi> isolates a text span for the bidirectional algorithm.
  • Use when: direction of inserted text is unknown or may be RTL inside LTR (or the reverse).
  • Default: omitting dir still means auto isolation.
  • Not bdo: force direction with <bdo>; isolate with <bdi>.

One line: wrap unpredictable names in <bdi> so nearby LTR/RTL text stays readable.

Default CSS Settings

User agents typically isolate the element for the Unicode bidirectional algorithm. A common idea looks like this:

default.css
bdi {
  unicode-bidi: isolate;
}

You may add color or weight for design, but do not replace <bdi> with a non-semantic CSS-only isolate for authoring.

Frequently Asked Questions

The bdi (Bidirectional Isolate) element tells the browser to treat its text separately from surrounding text in the Unicode bidirectional algorithm. That keeps mixed LTR/RTL content — such as usernames next to rankings — from getting scrambled.
No element-specific attributes. It supports global attributes. If you omit dir, bdi still behaves as if dir="auto" were set, so direction is inferred from the content.
bdi isolates text and lets the algorithm pick direction (auto by default). bdo overrides direction and requires an explicit dir of ltr or rtl.
Use it when you insert text whose direction you do not know in advance — user names, product titles from a database, comments, and similar dynamic strings — inside a sentence or list with fixed surrounding text.
unicode-bidi: isolate on a span can look similar, but HTML authors should prefer bdi. It is semantic, and browsers may ignore presentational CSS for bidi.
Usually no. Use bdi when mixed directionality (or unknown directionality) can affect nearby punctuation and numbers.

Next: bdo

Force left-to-right or right-to-left display when you must override direction.

bdo tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful