Skip to content
Related Articles

Related Articles

HTML | dir Attribute

Improve Article
Save Article
Like Article
  • Difficulty Level : Basic
  • Last Updated : 10 Aug, 2021

This attribute is used to specify the text direction of the element content.
Supported Tags: Ir supports all HTML elements. 

Syntax: 
 

<element dir = "ltr | rtl | auto">

Attribute Value: This attribute contains three value which are listed below: 
 

  • ltr: It is the default value. This value represent the text in Left-to-right text direction.
  • rtl: This value represent the text in right-to-left text direction.
  • auto: Let the browser figure out the text direction, based on the content.

Example 1: 
 

html




<!DOCTYPE html>
<html>
    <head>
        <title>dir attribute</title>
        <style>
            h1 {
                color:green;
            }
            h1, h2 {
                text-align:center;
            }
        </style>
    </head>
    <body>
        <h1>GeeksforGeeks</h1>
        <h2>dir attribute</h2>
        <p dir="rtl">GeeksforGeeks: A
        computer science portal for geeks</p>
 
    </body>
</html>

Output: 
 

Example 2: 
 

html




<!DOCTYPE html>
<html>
    <head>
        <title>dir attribute</title>
        <style>
            h1 {
                color:green;
            }
            h1, h2 {
                text-align:center;
            }
        </style>
    </head>
    <body>
        <h1>GeeksforGeeks</h1>
        <h2>dir attribute</h2>
        <p dir="ltr">GeeksforGeeks: A
        computer science portal for geeks</p>
 
    </body>
</html>

Output: 
 

Supported Browsers: The browser supported by dir attribute are listed below: 
 

  • Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari

 


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!