Skip to content
AITroveRead. Build. Understand.
Make this comfortable

HTML bdi: isolate an unknown text direction

Last updated: 5 Oct 20267 min read
tutorial
IntermediateBy AITrove Editorial

The bdi element isolates text whose writing direction is unknown from surrounding text.

When the element earns its place

A review queue includes customer names entered in several scripts. The page layout is left to right, but one name may contain right-to-left characters. Isolating each untrusted name keeps nearby punctuation and case numbers in a sensible order without forcing every name into the page direction. If a known phrase has a fixed language and direction, mark those facts directly instead of guessing from its first character.

html
<ul>
  <li>Case C-47 — <bdi>ليلى</bdi> — awaiting review</li>
  <li>Case C-52 — <bdi>Meera</bdi> — approved</li>
</ul>

Behavior boundary

Isolation changes text ordering behavior. It does not escape HTML, clean a submitted name, or make the application multilingual. Encode user-supplied strings before placing them inside these elements.

Cost and operational limits

Each isolated name adds one small element. The main cost is testing: mixed-script labels, copied text, and screen-reader output need review with real names and punctuation.

Common Mistakes

  • Do not use bdi as an HTML sanitizer.
  • Do not force dir=ltr on a name just because the page is left to right.
  • Do not omit language metadata for known-language paragraphs.

Connected lessons

Continue with HTML translate attribute: protect identifiers while localizing the surrounding text.

html
semantics
Storage details