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 »

Description

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
StringThe text direction of the element.

Browser Support

element.dir is supported in all browsers:

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes Yes

Copyright 1999-2023 by Refsnes Data. All Rights Reserved.