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>



Do you find this helpful?

Related articles