HTML | DOM Style direction Property
The Style direction property in HTML DOM is used to set or return the text direction of an element.
Syntax:
- It is used to set the text direction.
object.style.direction = "ltr|rtl|initial|inherit"
- It returns the text direction.
object.style.direction
Property Values:
- ltr: Specifies the direction as left to right which is also the default direction.
- rtl: Specifies the direction as right to left.
- initial: Sets the property to its default value.
- inherit: Inherits the property from the parent element.
Return Value: It returns the text direction of text content.
Example 1: This examplel set the text direction from right to left.
<!DOCTYPE html> <html> <head> <title> HTML DOM Style direction Property </title> </head> <body> <div> <!-- Style direction Property used here --> <p id = "para"> Welcome to GeeksforGeeks </p> </div> <input type = "button" value = "Click Here!" onclick = "myGeeks()" /> <!-- script to set text direction --> <script> function myGeeks() { document.getElementById("para").style.direction = "rtl"; } </script> </body> </html> |
Output:
Before Click on the button:

After Click on the button:

Example 2: This example returns the direction of text content.
<!DOCTYPE html> <html> <head> <title> HTML DOM Style direction Property </title> </head> <body> <div> <p id = "para" style = "direction: rtl"> Welcome to GeeksforGeeks </p> </div> <input type = "button" value = "Click Here!" onclick = "myGeeks()" /> <!-- script returns the content direction --> <script> function myGeeks() { alert(document.getElementById("para").style.direction); } </script> </body> </html> |
Output:
Before Click on the button:

After Click on the button:

Supported Browsers: The browser supported by Style direction property are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Recommended Posts:
- HTML | DOM Style right Property
- HTML | DOM Style top Property
- HTML | DOM Style filter Property
- HTML | DOM Style cursor Property
- HTML | DOM Style objectPosition Property
- HTML | DOM Style backgroundRepeat Property
- HTML | DOM Style outline Property
- HTML | DOM Style textAlignLast Property
- HTML | DOM Style objectFit Property
- HTML | DOM Style minWidth Property
- HTML | DOM Style order Property
- HTML | DOM Style animationName Property
- HTML | DOM Style animationDelay Property
- HTML | DOM Style transform Property
- HTML | DOM Style backgroundImage Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



