You’re reading the English version of this content since no translation exists yet for this locale. Help us translate this article!
The dir global attribute is an enumerated attribute that indicates the directionality of the element's text.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
It can have the following values:
ltr
, which means left to right and is to be used for languages that are written from the left to the right (like English);rtl
, which means right to left and is to be used for languages that are written from the right to the left (like Arabic);auto
, which lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element.
Usage notes
This attribute is mandatory for the <bdo>
element where it has a different semantic meaning.
-
This attribute is not inherited by the
<bdi>
element. If not set, its value isauto
. -
This attribute can be overridden by the CSS properties
direction
andunicode-bidi
, if a CSS page is active and the element supports these properties. -
As the directionality of the text is semantically related to its content and not to its presentation, it is recommended that web developers use this attribute instead of the related CSS properties when possible. That way, the text will display correctly even on a browser that doesn't support CSS or has the CSS deactivated.
-
The
auto
value should be used for data with an unknown directionality, like data coming from user input, eventually stored in a database.
Specifications
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'dir' in that specification. |
Living Standard | No change from latest snapshot, HTML 5.1 |
HTML 5.1 The definition of 'dir' in that specification. |
Recommendation | Snapshot of HTML Living Standard, no change from HTML5 |
HTML5 The definition of 'dir' in that specification. |
Recommendation | Snapshot of HTML Living Standard, from HTML 4.01 Specification it added the auto value, and is now a true global attribute. |
HTML 4.01 Specification The definition of 'dir' in that specification. |
Recommendation | Supported on all elements but <applet> , <base> , <basefont> , <bdo> , <br> , <frame> , <frameset> , <iframe> , <param> , and <script> . |
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
dir | Chrome Full support Yes | Edge No support No | Firefox Full support Yes | IE No support No | Opera Full support Yes | Safari Full support Yes | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support Yes | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support Yes |
Legend
- Full support
- Full support
- No support
- No support
See also
- All global attributes.
HTMLElement.dir
that reflects this attribute.