HTML DOM Element dir attribute

definition and usage

dir attribute sets or returns the dir attribute of the element.

dir attribute specifies text direction.

see also:

خصائص direction لـ Style

خصائص dir لـ HTML

خصائص direction لـ CSS

example

Example 1

Change the text direction of "myP" to "right-to-left":

document.getElementById("myP").dir = "rtl";

try it yourself

Example 2

Return the text direction of the document:

document.body.dir;

try it yourself

Example 3

Set the text direction of the document:

document.body.dir = "rtl";

try it yourself

syntax

Return dir attribute:

element.dir

Set dir attribute:

element.dir = "ltr|rtl|auto"

attribute value

value description
ltr left-to-right text direction (default).
rtl right-to-left text direction.
auto let the browser decide.

return value

type description
string the text direction of the element.

browser support

all browsers support element.dir

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
الدعم الدعم الدعم الدعم الدعم الدعم