dir Attribute specifies the direction of the element’s text.
dir is a Global Attribute, meaning it can be used with all HTML Elements.
dir global attribute specifies the direction of the element’s text.
<p dir="ltr">This text appears left to right.</p> <p dir="rtl">This text appears right to left.</p> <p dir="auto">The browser determines the direction.</p> <p dir="auto">المتصفح يحدد الاتجاه.</p>
This text appears left to right.
This text appears right to left.
The browser determines the direction.
المتصفح يحدد الاتجاه.
dirattribute causes any text within the element to be explicitly directionally isolated.
dirattribute can take the values
auto. See the Values section below for more details.
- This attribute is mandatory for the
- This attribute does not influence the directionality of any child
- This attribute can be overridden by the
unicode-bidiCSS properties. It is recommended to use the
dirattribute instead of CSS as it confers semantic meaning.
autovalue should only be used where the text direction is unknown, such as text derived from user input.
- The directionality of an element is relatively complex. The HTML Living Standard Specification sets out a complex order of steps to determine the directionality of any element.
Values can include:
ltr- This will display the text content within the element from left to right. This is useful for displaying languages such as English where the surrounding content may be written from right to left, such as on an Arabic website.
rtl- This will display the text content within the element from right to left. This is useful when displaying languages that should be written as such, for example, Arabic.
auto- This value lets the user agent or browser decide the correct directionality. It uses a basic algorithm to process the characters inside the element. When the user agent finds a character with a strong directionality, such as Arabic, that directionality is applied to the whole element.Warning
autostate is very crude in that it only looks at the first character of the text that carries strong directionality. The HTML specification recommends only using this value as a last resort.
dir HTML specification is as follows:
dir has the following browser support:
|Android Webview||Chrome Android||Firefox Android||Opera Android||iOS Safari||Samsung Internet|