Change the text direction of a <p> element to "right-to-left":
More "Try it Yourself" examples below.
The dir property sets or returns the value of the dir attribute of an element.
The dir attribute specifies the text-direction (reading order) of the element's content.
Tip: You can also use the style.direction property to set or return the text direction of an element.
Property | |||||
---|---|---|---|---|---|
dir | Yes | Yes | Yes | Yes | Yes |
Return the dir property:
Set the dir property:
Value | Description |
---|---|
ltr | Default. Left-to-right text direction |
rtl | Right-to-left text direction |
auto | Let the browser figure out the text direction, based on the content (only recommended if the text direction is unknown) |
Return Value: | A String, representing the text writing direction of the element |
---|
Get the text direction of a <p> element:
The result of x will be:
HTML reference: HTML dir Attribute
HTML DOM reference: Style direction Property
CSS reference: direction property