HTML DOM Element dir
Example
Change the text direction of "myP" to "right-to-left":
document.getElementById("myP").dir = "rtl";
Try it Yourself »
Return the text direction of a document:
document.body.dir;
Try it Yourself »
Set the text direction of a document:
document.body.dir = "rtl";
Try it Yourself »
Definition and Usage
The dir
property sets or returns an elements's dir attribute.
The dir
attribute specifies the text-direction.
Syntax
Return the dir property:
element.dir
Set the dir property:
element.dir = "ltr|rtl|auto"
Properties
Value | Description |
ltr | Left-to-right text direction (default). |
rtl | Right-to-left text direction. |
auto | Let the browser figure out. |
Return Value
Type | Description |
String | The text direction of the element. |
Browser Support
element.dir
is supported in all browsers:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |