dir
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
<element dir="ltr|rtl|auto">
Example
<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.
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.
Related Topics
- Global attributes
HTMLElement.dir
, which reflects this attribute.
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.
defer
The defer attribute in <script> tags delays script execution until after the document is fully parsed, improving loading time by preventing it from blocking page rendering.
download
The download attribute in HTML, when used with <a> tags, instructs the browser to download the linked file instead of opening it.