HTML bdi Tag: Control Text Direction in HTML

html bdi tag

The HTML bdi tag marks text that has an unknown or mixed direction. It makes sure that this part does not break the normal flow of the page.

What is the <bdi> Tag in HTML?

The <bdi> tag means bidirectional isolation. It tells the browser to treat that text part apart from the page around it.

Here is the tag:

<bdi>Text here</bdi>

You place the text inside the tag, and the browser will keep it in the right direction without change to nearby content.

You can use the bdi tag when you need to show names, codes, or words that may come from another language. This helps avoid text order mix-up.

The bdi tag does not use special attributes. It follows normal HTML rules and supports global attributes like class, id, or style.

The bdi tag works in most browsers, such as Chrome, Edge, Firefox, Opera, and Safari. Old versions of Internet Explorer do not support it.

The Difference Between <bdi> and <bdo> Tags

The bdi tag lets the browser decide the text direction in an isolated way. The <bdo> tag forces text into a set direction that you choose.

Here are the key differences:

TagActionControlUse Case
<bdi>Isolate text and keep natural directionThe author sets itMixed language text
<bdo>Force text to go left or rightAuthor sets itReverse or override direction

You use bdi when you show user names or content you do not control. You use <bdo> when you must override normal direction and force a strict layout.

Examples of <bdo> Tag in HTML

Isolate Username in Mixed Text:

User: <bdi>مرحبا</bdi> joined the chat.

In this case, The word in Arabic stays safe inside the tag. It does not affect the order of other words. The page may show mixed letters without this.

Keep Code Safe Inside Text:

Code: <bdi>123-XYZ</bdi> saved in record.

This code stays in order without change. The tag makes sure that numbers and letters stay aligned, even when they come with text from right to left.

Compare bdi and <bdo>:

<bdi>שלום</bdi>  
<bdo dir="rtl">hello</bdo>

The first tag shows you Hebrew text. This keeps the remaining text in the same place, and the second text is RTL.

User Data in Multi-Language Page:

Post by <bdi>محمود</bdi> at 10:00 AM

Wrapping Up

You learned the role of the HTML bdi tag and the way it differs from the <bdo> tag. Here is a quick recap:

  • The <bdi> tag isolates unknown or mixed text.
  • The <bdo> tag forces direction control.
  • You can use bdi for names or user text.
  • You can use <bdo> when you need a strict order.

FAQs

How to use <bdi> tag in HTML?

You can use <bdi> to isolate text that may have a different direction from its surrounding text.
<p>User: <bdi>مرحبا</bdi> 10 points</p>
The browser will display it correctly without breaking the text flow.

What is the difference between <bdi> and <bdo> in HTML?

The <bdi> tag isolates text so the browser can determine direction automatically, while <bdo> forces a specific direction.
<p>With bdi: <bdi>مرحبا</bdi></p>  
<p>With bdo: <bdo dir="rtl">مرحبا</bdo></p>

Can I style <bdi> tag with CSS?

Yes. The <bdi> tag behaves like inline elements, so you can style it with CSS properties.
<bdi style="color:red; font-weight:bold;">مرحبا</bdi>

Similar Reads

HTML object Tag: How to Embed External Objects with Examples

Use the HTML object tag to embed different types of external files into your webpage. It works for videos and…

HTML Label Tag: How It Works with Examples

Forms need instructions so users know what to enter. You use the HTML label tag to give names to input…

HTML id Attribute: How to Assign Unique Identifiers to Elements

The id attribute adds a unique name to an HTML element. It helps with CSS and JavaScript in the page.…

HTML a Tag: How to Add Links to Web Page with Examples

The HTML a tag allows you to create links that move users from one page or resource to another. Understand…

HTML <cite> Tag: How to Reference Sources

The HTML <cite> tag is a small but important tool for marking up the title of a creative work. You…

HTML Header Tag: The Complete Guide with Examples

The header tag defines the top part of a page or a section in HTML. It usually holds a heading…

HTML embed Tag: How to Embed External Media in Web Pages

The HTML embed tag is used to display media content, such as videos or audio. It can also display PDFs…

HTML meta Tags for SEO

In this article, you will learn what HTML meta tags are and how they work. You also see how they…

HTML List Tag: Understand the ul, ol, and dl Lists

HTML has three main list tags: <ul>, <ol>, and <dl>. Each one shows a different kind of group. In this…

HTML Article Tag: How to Create Semantic Content

Semantic article tag in HTML uses clear tags that show the role of each part. These tags tell browsers and…

Previous Article

PHP array_diff_ukey Function: How it Works with Examples

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *


Subscribe to Get Updates

Get the latest updates on Coding, Database, and Algorithms straight to your inbox.
No spam. Unsubscribe anytime.