HTML dir Attribute
The dir attribute is a part of Global Attributes and specifies the text direction of an element’s content. Read and find out on what elements it can be used.
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, typically using the first strong directional character.
Syntax
Syntax of HTML dir Attribute
<tag dir="ltr|rtl|auto">content</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
Practice
What is the purpose of the HTML 'dir' attribute according to the page from w3docs.com?