HTML Dir Attribute Tutorial with Examples

View more Tutorials:

Follow us on our fanpages to receive notifications every time there are new articles. Facebook Twitter

1- HTML Direction

The HTML language is created to ensure that it can create the websites suitable for all cultures. Arabic is one of the four most popular languages in the world. The contents in Arabic books and websites are written in the Right To Left (RTL) direction, which can be quite strange to the remaining countries. 
For example, the following is an website of IRAQ government .
To display the content of an element  from right to left (RTL), we use the dir='rlt' attribute:

<!DOCTYPE html>
      <title>HTML Dir Attribute</title>
      <meta charset="UTF-8"/>
          div {
            border: 1px solid green;
            padding: 5px;
            margin: 10px 0;
       <h1>HTML Dir Attribute</h1>
           <h3>LTR (Left-to-Right) Direction! (Default)</h3>
           I am a Text.
       <div dir = "rtl">
          <h3>RTL (Right-to-Left) Direction!</h3>
          I am a Text.
Most browsers support the dir attribute, except for Internet Explorer and Edge

<element dir = "ltr|rtl|auto">..</element>
ltrUsed for the languages written in left to right direction, for example, English
rltUsed for the languages written in right to left direction, for example, Arabic.
autoA browser will be based on user agent to decide. It uses a basic algorithm to parse the content inside an element until it finds a character with strong directionality, and then apply that direction to all element.
Note: HTML5 supports the dir attribute for all elements while HTML4 supports this attribute for all elements except for <base>, <br>, <frame>, <frameset>, <hr>, <iframe>, <param>, <script>.

View more Tutorials: