dir

The dir attribute in HTML indicates the text direction of an element's content, using values like ltr for left-to-right and rtl for right-to-left, influencing how languages are displayed.

dir Attribute

The dir global attributes defines the text direction for an element’s content. It determines whether the text flows from left to right (ltr) or right to left (rtl).

Syntax

index.html
<element dir="ltr|rtl|auto">

Example

This text is left-to-right.
index.html
<div dir="ltr">This text is left-to-right.</div>

Values

  • ltr – Displays text from left to right (e.g., English).
  • rtl – Displays text from right to left (e.g., Arabic).
  • auto – Determines direction based on the first strong character.

Inheritance

If the dir attribute is not explicitly set, the element inherits the text direction from its parent unless otherwise specified further up the document structure.

The dir attribute defines text direction, particularly left-to-right (ltr) and right-to-left (rtl).

dir Attribute Values

  • ltr – Text flows from left to right (default).
  • rtl – Text flows from right to left.
  • auto – The user agent determines the text direction based on the content.

Conclusion

The dir attribute plays a crucial role in handling text direction for multilingual web pages. By setting values like ltr, rtl, or auto, developers can enhance text readability and accessibility. When omitted, the attribute inherits its value from parent elements, making it a flexible and effective tool for structuring multilingual content.