HTML dir Attribute

The dir attribute specifies the directionality of the element‘s text. The text direction can be set to left-to-right (ltr) or right-to-left (rtl).

Example

#

A dir on a paragraph.
The text displays right-to-left.

This text is displayed from right-to-left.

<p dir="rtl" 
   style="background-color: #f6f8ff; padding: 25px;">
   This text is displayed from right-to-left.
</p>

Using dir

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

The text direction can be set to left-to-right (ltr) or right-to-left (rtl).

Here is a list of the languages that are written from right-to-left (rtl):

  • Arabic
  • Aramaic
  • Azeri
  • Dhivehi/Maldivian
  • Hebrew
  • Kurdish (Sorani)
  • Persian/Farsi
  • Urdu

Note:   dir is a global attribute that can be applied to any tag.


Syntax

<tag dir="ltr | rtl | auto" />

Values

#

Value Description
ltr Sets the text direction from left-to-right. This is the default.
rtl Sets the text direction from right-to-left.
auto Specifies that the browser will decide the text direction.

More Examples

Two right to left languages: Arabic and Hebrew.
With dir='auto', the browser correctly identifies the directionality.

سيتم عرض هذا النص من اليمين إلى اليسار.

טקסט זה יוצג מימין לשמאל.

<p dir="auto" 
   style="background-color: #f6f8ff; padding: 25px;">
   سيتم عرض هذا النص من اليمين إلى اليسار.
</p>

<p dir="auto" 
   style="background-color: #f6f8ff; padding: 25px;">
   טקסט זה יוצג מימין לשמאל.
</p>

Browser support

Here is when dir support started for each browser:

Chrome
8 Dec 2010
Firefox
41 Sep 2015
IE/Edge
12 Jul 2015
Opera
15 Jul 2013
Safari
5.1 Jul 2011

You may also like



Guides