HTML dir Global Attribute
The dir attribute sets the text direction of an element: ltr (left to right), rtl (right to left) or auto, where the browser decides from the content.
Description
The dir HTML global attribute specifies the text direction of the element's content. It can be used on any HTML element, but it is especially useful for elements that contain text in multiple languages or mixed text directions.
The dir attribute can have three values:
ltr: Left-to-right text direction.rtl: Right-to-left text direction.auto: The user agent decides the text direction, based on the content.
For example, the following code would specify that the content of the <p> element is in a right-to-left text direction:
<p dir="rtl">This is some right-to-left text.</p>
If the attribute is not set, the element inherits the direction of its parent; the root element defaults to ltr. The CSS direction property can also change the direction, but the dir attribute is recommended, because the direction is part of the content and not only its presentation.
Here is an example of how to use the dir attribute to create a two-column layout with one column in left-to-right text direction and the other column in right-to-left text direction:
<div style="display: flex; flex-direction: row;">
<div dir="ltr">This is some left-to-right text.</div>
<div dir="rtl">This is some right-to-left text.</div>
</div>
The dir attribute is an important tool for creating web pages that are accessible to users who speak languages that use different text directions.
Syntax
<element dir="ltr | rtl | auto">
Values
- ltrDetermines the direction of text from left to right. This is the default for the root element.
- rtlDetermines the direction of the text from right to left.
- autoThe direction of the text is determined automatically by the browser based on the content (recommended only if the direction of the text is unknown).
Example
Browser Support
The following information will show you the current browser support for the HTML dir global attribute. Hover over a browser icon to see the version that first introduced support for this HTML global attribute.
Desktop





Tablets & Mobile





