HTML <bdo> Bidirectional Override


The <bdo> tag in HTML stands for "Bidirectional Override." It is used to explicitly control the directionality of text within a document, overriding the default bidirectional text algorithm. This tag allows you to specify the direction in which text should be displayed, either left-to-right (LTR) or right-to-left (RTL), regardless of the surrounding text's direction.

Syntax:

<bdo dir="ltr">Left-to-right text</bdo> <bdo dir="rtl">Right-to-left text</bdo>

Attributes:

  • dir: Specifies the direction of the text. It can take one of the following values:
    • ltr (left-to-right): Text is displayed from left to right, which is the default direction for languages like English and French.
    • rtl (right-to-left): Text is displayed from right to left, which is the default direction for languages like Arabic and Hebrew.

Example:

<p>Normal text direction, and <bdo dir="rtl">1234</bdo> forced RTL text direction.</p>

In this example:

  • The <bdo dir="rtl">1234</bdo> tag forces the number "1234" to be displayed in right-to-left direction, regardless of the surrounding left-to-right text.

Use Cases:

  1. Mixed Languages: When you have a mix of languages with different text directions and need to ensure that each segment is displayed correctly.
  2. Dynamic Content: When inserting content dynamically that may not follow the default text direction, and you want to explicitly control its display direction.
  3. Embedded Text: For text within a different language or script that needs to be rendered in its natural direction.

Comparison with <bdi>:

  • <bdi> (Bidirectional Isolation): Isolates a segment of text so that its directionality is preserved, but does not override the direction of surrounding text. It helps maintain correct display without affecting the text around it.
  • <bdo> (Bidirectional Override): Overrides the directionality of the text enclosed within it, forcing it to be displayed in a specified direction regardless of surrounding content.

Example with Mixed Directions:

<p>This is an example of <bdo dir="rtl">mixed-direction</bdo> text.</p>

In this example, "mixed-direction" will be displayed in right-to-left direction, even though it is within a left-to-right context.

Accessibility and SEO:

  • Accessibility: The <bdo> tag helps ensure that text is displayed in the intended direction, which is important for users with visual impairments who rely on proper text rendering.
  • SEO: The use of <bdo> does not directly impact SEO but helps maintain a consistent and accurate presentation of multilingual content, which can improve user experience and engagement.