Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

HTML | DOM dir Property

  • Last Updated : 22 Jul, 2021

The DOM dir Property is used to set or return the value of dir attribute in an Element. It defines a direction of the text in an Element Content.


Return Values: It returns the the direction of the text. 

HTMLElementObject.dir = "ltr|rtl|auto"


  • ltr: It is a default Value and used to return the text-direction towards left-to-right.
  • rtl: It is used to return the right-to-left text-direction.

Example-1: To change the direction of the text. 


<!DOCTYPE html>
        HTML | DOM dir Property
        button {
            margin-left: 270px;
    <h1 style="color:green;font-weight:bold;text-align:center;">
    <h2 style="color:green;font-weight:bold;text-align:center">
    DOM dir Property
    <p id="sudo" dir="ltr">
        GeeksForGeeks is a good website for
        learning computer science.
    <button onclick="geeks()">Submit</button>
    <p id="GFG"></p>
        function geeks() {
        var g =    document.getElementById("sudo").dir = "rtl";
            document.getElementById("GFG").innerHTML = "The text-direction was changed  from ltr to " + g;


Before clicking on button:

After clicking on button: 


Example-2: To get the direction of the text. 


Before clicking on button:

After clicking on button: 

Supported Browsers: The browser supported by DOM Dir property are listed below: 

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!