Style direction attribute

Definition and Usage

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

See also:

CSS Tutorial:CSS 文本

CSS Reference Manual:Direction attribute

HTML Reference Manual:HTML dir 属性

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 direction attribute:

object.style.direction

Set direction attribute:

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

Attribute 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: String that represents the text direction of the element.
CSS Version: CSS2

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
支持 支持 支持 支持 支持