Favorites

HTML dir Global Attribute

dir
HTML Global AttributeThis global attribute is supported by all modern browsers.
Updated 22nd November 2026

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.

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee

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

<p dir="ltr">This text will be displayed from left to right.</p> 
<p dir="rtl">This text will be displayed from right to left. </p>
<p dir="auto">The direction of the text is determined automatically by the browser.</p>
Open in editor

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.

This global attribute is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee