0Pricing
HTML Academy · Lesson

The bdi and bdo Elements

Isolate and override text directionality with bdi and bdo.

The bdi and bdo Elements is a free HTML Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the HTML Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why Bidi Control Elements?

The Unicode Bidirectional Algorithm normally handles mixed-direction text well, but sometimes you need to override it — to isolate a user-supplied name from changing the direction of surrounding text, or to force a specific direction in a code block.

The bdi Element

<bdi> (bidirectional isolation) treats its contents as a separate bidi context. The direction of text inside <bdi> cannot affect the direction of text outside it, and vice versa.

<p>User <bdi>{username}</bdi> posted at 12:34</p>

Use Case: User Names

A list of users mixing English and Arabic names risks the Arabic names "leaking" their RTL flow into the surrounding text. Wrapping each name in <bdi> isolates it: the layout stays consistent regardless of what direction each name happens to be.

The bdo Element

<bdo dir="rtl"> (bidirectional override) forces a specific direction on its contents, overriding the natural bidi resolution. Use it when you want to display text in a non-natural direction — for example, to render code snippets in LTR within an RTL page.

<bdo dir="ltr">someEnglishCode();</bdo>

Difference From dir

The dir attribute on a regular element sets a base direction and the bidi algorithm still applies inside. <bdo> turns off the bidi algorithm for its contents — every character flows strictly in the specified direction regardless of its script.

When to Use bdi

Anytime you embed user-generated text into surrounding chrome — names in chat headers, usernames in comments, titles in feed items. The isolation guarantees the chrome layout is unaffected by what the user typed.

When to Use bdo

Rarely. The main legitimate use is teaching about bidirectional text (showing what a string looks like reversed) or correcting badly-tagged data where the natural bidi resolution produces the wrong visual order.

Combined With dir="auto"

For user-content of unknown direction, combine <bdi dir="auto"> for double safety: the auto detection picks a base direction from the content, and the bdi prevents that direction from leaking out into surrounding text.

Browser Support

bdi and bdo are supported in every modern browser. They are part of HTML5 and have been stable for years. Older versions of IE lack bdi but they are functionally obsolete; modern sites can use bdi freely.

Accessibility

Screen readers respect bidi isolation: text inside <bdi> is announced in its own language voice (when lang is set), without the surrounding context bleeding in. bdi also helps text-to-speech generate appropriate pauses around isolated phrases.

Common Pattern: i18n in Templates

Templates with placeholders ("Welcome, {name}") should wrap the placeholder in <bdi>: Welcome, <bdi>{name}</bdi>. Any user name — English, Arabic, mixed — renders correctly without disturbing the rest of the greeting.

Knowledge Check

What is the practical difference between and ?

Summary

bdi isolates a section's text direction from affecting its surroundings — use for embedded user content like names in templates. bdo forces a specific direction overriding bidi, rarely needed outside teaching examples. Combine bdi with dir="auto" for safe handling of user-provided text in unknown languages.

Frequently asked questions

Is the “The bdi and bdo Elements” lesson free?

Yes — the full text of “The bdi and bdo Elements” is free to read here on the web, and the HTML Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the HTML Academy course, upgrade to CoddyKit PRO.

What will I learn in “The bdi and bdo Elements”?

Isolate and override text directionality with bdi and bdo. You practise HTML Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start HTML Academy?

No prior experience is required. HTML Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “The bdi and bdo Elements” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this HTML Academy lesson?

Yes. Every HTML Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. The lang Attribute and Screen Readers
  2. dir=rtl for Right-to-Left Text
  3. The bdi and bdo Elements
  4. charset and Unicode Handling Special Characters
← Back to HTML Academy