# HTML Global Attribute: dir
The `dir` attribute is an HTML global attribute used to specify the text direction of an element's content. It is essential for designing multi-lingual websites, particularly when dealing with Right-to-Left (RTL) languages such as Arabic, Hebrew, Persian, or Urdu.
---
## Definition and Usage
The `dir` attribute determines the directionality of text, inline graphics, and form elements within an HTML document.
While CSS properties like `direction` can also control text flow, using the HTML `dir` attribute is highly recommended for accessibility and semantic markup. This ensures that the content remains readable and correctly structured even if CSS fails to load.
---
## Syntax
```html
```
### Attribute Values
| Value | Description |
| :--- | :--- |
| `ltr` | **Default.** Left-to-right text direction. Used for languages like English, Spanish, Chinese, etc. |
| `rtl` | Right-to-left text direction. Used for languages like Arabic, Hebrew, and Persian. |
| `auto` | Let the browser decide the text direction based on the content. (Recommended only when the text direction of the dynamic content is unknown). |
---
## Code Examples
### Example 1: Basic Right-to-Left (RTL) Text Direction
In this example, we use the `` (Bi-Directional Override) element along with the `dir="rtl"` attribute to reverse the text flow.
```html
HTML dir Attribute Example
This paragraph is rendered from left to right (default).
This text will flow from right to left!
```
### Example 2: Handling Dynamic Content with `auto`
When displaying user-generated content where the language is unpredictable, setting `dir="auto"` allows the browser to analyze the first strongly typed character and adjust the layout accordingly.
```html
Ω
Ψ±ΨΨ¨Ψ§ Ψ¨Ψ§ΩΨΉΨ§ΩΩ
(Hello World)
Hello World (Ω
Ψ±ΨΨ¨Ψ§ Ψ¨Ψ§ΩΨΉΨ§ΩΩ
)
```
---
## HTML 4.01 vs. HTML5 Differences
* **HTML5:** The `dir` attribute is a **global attribute** and can be applied to any HTML element (though it may not have a visual effect on all elements).
* **HTML 4.01:** The `dir` attribute could **not** be used with the following elements: ``, `
`, ``, `