The dir attribute specifies the directionality of the element‘s text.
Possible values are left-to-right (ltr
) or right-to-left (rtl
).
A dir
on a paragraph.
The text displays right-to-left. Note the position of the period.
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>
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):
Note: dir
is a global attribute that can be applied to any tag.
<tag dir="ltr | rtl | auto" />
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. |
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>
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 |