HTML DOM dir Property
Example
Change the text direction of a <p> element to "right-to-left":
document.getElementById("myP").dir = "rtl";
Try it yourself »
More "Try it Yourself" examples below.
Definition and Usage
The dir property sets or returns the value of the dir attribute of an element.
The dir attribute specifies the text-direction (reading order) of the element's content.
Tip: You can also use the style.direction property to set or return the text direction of an element.
Browser Support
Property | |||||
---|---|---|---|---|---|
dir | Yes | Yes | Yes | Yes | Yes |
Syntax
Return the dir property:
HTMLElementObject.dir
Set the dir property:
HTMLElementObject.dir="ltr|rtl|auto"
Property Values
Value | Description |
---|---|
ltr | Default. Left-to-right text direction |
rtl | Right-to-left text direction |
auto | Let the browser figure out the text direction, based on the content (only recommended if the text direction is unknown) |
Technical Details
Return Value: | A String, representing the text writing direction of the element |
---|
More Examples
Example
Get the text direction of a <p> element:
var x = document.getElementById("myP").dir;
The result of x will be:
rtl
Try it yourself »
Related Pages
HTML reference: HTML dir Attribute
HTML DOM reference: Style direction Property
CSS reference: direction property