- Home
- /
- Tutorials
- /
- HTML Tutorial
- /
- HTML <bdi> Tag
HTML Tags
HTML <bdi> Tag
The bdi tag protects the layout of your sentence from text whose direction you do not know, like a username in Arabic placed in an English sentence. Without it, a right-to-left name can scramble the punctuation and numbers around it.
The name means bidirectional isolation. The browser works out the direction of the text inside on its own, and keeps that text from affecting anything outside it. Compare it with the bdo tag, which forces a direction instead.
Syntax
html
<bdi>Text with different direction</bdi>It has no attributes of its own. You can add dir, but leaving it out is the point: the browser decides from the content.
Example
html
<!DOCTYPE html>
<html>
<head>
<title>BDI Tag Example</title>
<style>
bdi {
background-color: #f0f0f0;
padding: 4px 6px;
border-radius: 4px;
color: #2c3e50;
}
table {
border-collapse: collapse;
margin-top: 10px;
}
td, th {
border: 1px solid #ccc;
padding: 8px 12px;
text-align: left;
}
</style>
</head>
<body>
<h1>HTML <bdi> Tag Example</h1>
<p>The <code><bdi></code> tag helps when you have mixed-direction text, such as English and Arabic usernames.</p>
<table>
<tr>
<th>Username</th>
<th>Score</th>
</tr>
<tr>
<td><bdi>John</bdi></td>
<td>95</td>
</tr>
<tr>
<td><bdi>إيمان</bdi></td> <!-- Arabic name (right-to-left) -->
<td>89</td>
</tr>
<tr>
<td><bdi>Ali_العربي</bdi></td> <!-- Mixed direction -->
<td>92</td>
</tr>
</table>
</body>
</html>The table lists usernames in English, Arabic and a mix of both. Each name is wrapped in <bdi>, so whatever its direction, it stays inside its own cell and the scores line up correctly.
The problem bdi solves
Imagine a comment list that shows "username: 3 comments". If the username is Arabic, the browser's direction rules can move the colon and the number to the wrong side, producing something like "3 :username comments". Wrapping the name in <bdi> keeps the rest of the line in order.
User-generated names inside a sentence
html
<li><bdi>إيمان</bdi>: 3 comments</li>
<li><bdi>John</bdi>: 5 comments</li>That is why <bdi> matters most for text you do not control: names, comments, search terms, product titles from users.
Browser Support
Chrome | Edge | Firefox | Safari | Opera | IE9+ |
|---|---|---|---|---|---|
| Yes | Yes | Yes | Yes | Yes | Yes |
HTML <bdi> Tag exercises
Isolate a name
Write this paragraph. The name comes from a visitor and may be in any script, so isolate only the name: Winner: Ada with 12 points
Result
