Style direction attribute

Definition and usage

direction Sets or returns the text direction (reading order) of the element's content.

See also:

CSS Tutorial:CSS Text

CSS Reference Manual:direction attribute

HTML Reference Manual:HTML dir Attribute

HTML DOM Reference Manual:HTML DOM dir attribute

Instance

Example 1

Set the text direction of the <p> element to "from right to left":

document.getElementById("myP").style.direction = "rtl";

Try it yourself

Example 2

Return the text direction of the <p> element:

alert(document.getElementById("myP").style.direction);

Try it yourself

Syntax

Return the direction attribute:

object.style.direction

Set the direction attribute:

object.style.direction = "ltr|rtl|initial|inherit"

Property value

Value Description
ltr Text flows from left to right. Default.
rtl Text flows from right to left.
initial Set this property to its default value. See initial.
inherit Inherit this property from its parent element. See inherit.

Technical details

Default value: ltr
Return value: A string representing the text direction of the element.
CSS Version: CSS2

Browser support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support