HTML dir Attribute

The HTML dir attribute specifies the text direction of an element’s content. It is important for enabling HTML in right-to-left scripts (e.g. Arabic, Hebrew, etc.). Numerous languages are written with these scripts.

You can use this attribute on any HTML element. It is a part of the Global Attributes.

The dir attribute can have the following values:

  • ltr: displays the text in left-to-right text direction. It is the default value.
  • rtl: displays the text in right-to-left text direction.
  • auto: lets the browser determine the text direction, based on the content.

Syntax

<tag dir="ltr|rtl|auto"></tag>

Example of the HTML dir attribute:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    <p dir="rtl">Example of the HTML "dir" attribute:</p>
  </body>
</html>

Practice Your Knowledge

What is the purpose of the HTML 'dir' attribute according to the page from w3docs.com?

Quiz Time: Test Your Skills!

Ready to challenge what you've learned? Dive into our interactive quizzes for a deeper understanding and a fun way to reinforce your knowledge.

Do you find this helpful?