The <bdo> element (Bi-Directional Override) forces a specific text direction inside its scope. By using dir="ltr" or dir="rtl", you override the browser’s normal bidirectional algorithm. This is useful for short runs of mixed text (like codes, numbers, or acronyms) where the default direction would produce confusing visual order.
Remember: <bdo> changes how text is rendered (visual order), not the underlying characters. It should be used sparingly and precisely.
dir="ltr" or dir="rtl") for a short span of text.dir is mandatory on <bdo>; without it, the tag has no effect.dir="auto"/<bdi> for unknown user input.direction + unicode-bidi: bidi-override can emulate <bdo>.Typical usage for overriding a small run of text:
<p>Normal: Hello 123 ABC</p>
<p>With BDO (rtl): <bdo dir="rtl">Hello 123 ABC</bdo></p>
In real projects you combine base element directions with local overrides:
<!-- In an RTL paragraph, force a product code to LTR -->
<p dir="rtl">الرمز: <bdo dir="ltr">SKU-AX9-42</bdo></p>
<!-- CSS equivalent of BDO -->
<span style="direction: rtl; unicode-bidi: bidi-override;">Hello 123 ABC</span>
dir on elements sets the base direction (ltr, rtl, or auto) on blocks such as <html> or <p>.direction: rtl; unicode-bidi: bidi-override; is effectively the same as <bdo dir="rtl"> for that span.
<p>Normal: Hello 123 ABC</p>
<p>With BDO (rtl): <bdo dir="rtl">Hello 123 ABC</bdo></p>
<!-- In an RTL paragraph, force a product code to LTR -->
<p dir="rtl">الرمز: <bdo dir="ltr">SKU-AX9-42</bdo></p>
<!-- CSS equivalent of BDO -->
<span style="direction: rtl; unicode-bidi: bidi-override;">Hello 123 ABC</span>
Sample: Hello 123 ABC مرحبا
النص مع كود المنتج: SKU-AX9-42
Without the <bdo dir="ltr"> override, the hyphens and digits in the product code might appear in a strange order when mixed inside RTL text.
Author: محمد — posted 5 min ago
Author: Alex — posted 2 min ago
Using <bdi> keeps the em dash and “posted …” phrase stable regardless of whether the name is LTR or RTL.
<bdo> to short spans (codes, acronyms), not whole paragraphs.dir. <bdo> without dir does nothing.<bdi> or dir="auto".<bdo> changes display order, not the actual characters, language, or pronunciation.<bdo dir="rtl">...<bdo dir="ltr">... can quickly become unreadable.<html dir="ltr|rtl"> for pages written primarily in one direction.direction plus unicode-bidi: bidi-override can be applied via CSS instead of HTML.dir="rtl" and wrap a left-to-right SKU in <bdo dir="ltr">. Compare the display with and without <bdo>.<bdo dir="rtl"> span with a <span> that uses style="direction: rtl; unicode-bidi: bidi-override;" and confirm the behavior is the same.<bdi> around each name to observe punctuation flow.dir="auto" on a <span> that you dynamically fill with user text (e.g., from a form field) and see how the browser chooses direction automatically.<bdo> (Bi-Directional Override) forces a specific visual direction (ltr or rtl) for a span of text.dir is required on <bdo>, and you should avoid wrapping large blocks or entire pages.<bdi> and dir on elements work alongside <bdo> to handle mixed-direction content safely.