English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML Tag List

HTML dir attribute

The global attribute dir is an enumeration attribute that indicates the text direction of an element. Its values are as follows: ltr, means from left to right, used for languages written from left to right (such as English); rtl, means from right to left, used for languages written from right to left (such as Arabic); auto, means the direction is determined by the user agent. It applies a basic algorithm when parsing characters in an element until it finds a character with a strong direction, and then applies that direction to the entire element.

HTML Global Attributes

Online Example

Paragraphs with text direction from left to right and from right to left:

!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Usage of HTML dir Attribute (Basic Tutorial Website oldtoolbag.com)</title>
</head>
<body>
<bdo dir="ltr">Text direction is from left to right!/bdo><br>
bdo dir="rtl">Text direction from right to left!/bdo>
</body>
</html>
Test to see ‹/›

Browser Compatibility

IEFirefoxOperaChromeSafari

All major browsers support the dir attribute

Definition and Usage

The dir attribute specifies the text direction of the element's content.

HTML 4.01 With HTML5Differences

In HTML5 In, the dir attribute can be used for any HTML element (it will validate any HTML element. But it may not be useful).

In HTML 4.01 In, the dir element cannot be used: <base>, <br>, <frame>, <frameset>, <hr>, <iframe>, <param>, and <script>.

Syntax

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

Attribute value

ValueDescription
ltrDefault. Text direction from left to right.
rtlText direction from right to left.
autoLet the browser determine the text direction based on the content. Recommended to use only when the text direction is unknown.

HTML Global Attributes