The HTMLElement.dir property gets or sets the text writing directionality of the content of the current element.
The text writing directionality of an element is which direction that text goes (for support of different language systems). Arabic languages and Hebrew are typical languages using the RTL directionality.
An image can have its dir property set to "rtl" in which case the HTML attributes title and alt will be formatted and defined as "rtl".
When a table has its dir set to "rtl", the column order is arranged from right to left.
When an element has its dir set to "auto", the direction of the element is determined based on its first strong directionality character, or default to the directionality of its parent element.
var currentWritingDirection = elementNodeReference.dir; elementNodeReference.dir = newWritingDirection;
Possible values for dir are ltr, for left-to-right, rtl, for right-to-left, and auto for specifying that the direction of the element must be determined based on the contents of the element.
var parg = document.getElementById("para1");
parg.dir = "rtl";
// change the text direction on a paragraph identified as "para1"
| Specification | Status | Comment |
|---|---|---|
| HTML Living Standard The definition of 'dir' in that specification. | Living Standard | No change from Document Object Model (DOM) Level 2 HTML Specification. |
| Document Object Model (DOM) Level 2 HTML Specification The definition of 'dir' in that specification. | Obsolete | No change from Document Object Model (DOM) Level 1 Specification. |
| Document Object Model (DOM) Level 1 Specification The definition of 'dir' in that specification. | Obsolete | Initial definition. |
| Desktop | ||||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
| Basic support | ? | Yes | 1 | ? | ? | ? |
| Mobile | |||||||
|---|---|---|---|---|---|---|---|
| Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
| Basic support | Yes | Yes | Yes | 4 | ? | ? | ? |
document.dir<dir> element and the HTML dir global attribute.direction property:dir pseudo-class
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dir