X
HOME HTML5 CSS3 JAVASCRIPT SQL PHP5 JQUERY ANGULAR BOOTSTRAP3 XML MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

HTML DOM dir Property

HTMLElement Object Reference Element Object

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


Examples

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


HTMLElement Object Reference Element Object


Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook