Style direction attribute

Definition and usage

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

See also:

CSS tutorial:CSS tekst

CSS reference manual:Direction attribute

HTML reference manual:HTML dir egenskab

HTML DOM reference manual:HTML DOM dir attribute

Instance

Example 1

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

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

Try it yourself

Example 2

Returns the text direction of the <p> element:

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

Try it yourself

Syntax

Return direction attribute:

object.style.direction

Set 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 Sets this property to its default value. See initial.
inherit Inherits this property from its parent element. See inherit.

Technical details

Default value: ltr
Return value: A string that represents the text direction of the element.
CSS version: CSS2

Browser supports

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