**`<bdo>`** requires a **`dir`** attribute — `ltr` (left-to-right) or `rtl` (right-to-left) — and forcibly overrides how its content is visually ordered, regardless of what the browser's normal bidirectional (bidi) text algorithm would otherwise decide based on the actual characters. This is different from just setting `dir` on any element for genuinely right-to-left languages like Arabic or Hebrew (which lets the browser apply proper bidi rules); `<bdo>` explicitly forces raw visual reordering, useful mainly for demonstrating bidi behavior or handling unusual edge cases where automatic detection produces the wrong result.
1Understanding <bdo>
`<bdo>` requires a `dir` attribute — ltr (left-to-right) or rtl (right-to-left) — and forcibly overrides how its content is visually ordered, regardless of what the browser's normal bidirectional (bidi) text algorithm would otherwise decide based on the actual characters. This is different from just setting dir on any element for genuinely right-to-left languages like Arabic or Hebrew (which lets the browser apply proper bidi rules); <bdo> explicitly forces raw visual reordering, useful mainly for demonstrating bidi behavior or handling unusual edge cases where automatic detection produces the wrong result.
For actual right-to-left content in a real language like Arabic or Hebrew, set dir="rtl" on a normal container (like the <html> or a <div>) rather than reaching for <bdo> — the browser's standard bidi algorithm already handles real RTL languages correctly.
<p>The word is normally: <bdo dir="rtl">HELLO</bdo></p>2Practical Example
Here is a real-world application of <bdo> showing how it is used in production HTML.
<!-- Correct way to mark a whole document as right-to-left (not using bdo) -->
<html dir="rtl" lang="ar">
<body>
<p>مرحبا بالعالم</p>
</body>
</html>3Best Practices
Follow these guidelines when working with <bdo>:
1. Use <bdo> mainly for forcing an explicit override, not for normal RTL-language content
2. Set dir="rtl" on <html> or a container element for genuine right-to-left language support instead
3. Reserve <bdo> for edge cases like mixed-direction text that the automatic algorithm gets wrong
Tip: For actual right-to-left content in a real language like Arabic or Hebrew, set dir="rtl" on a normal container (like the <html> or a <div>) rather than reaching for <bdo> — the browser's standard bidi algorithm already handles real RTL languages correctly.
<p>The word is normally: <bdo dir="rtl">HELLO</bdo></p>