dir
Text direction: left to right, right to left, or automatic.
- Applies to
- All HTML elements
Example
#<p dir="ltr">Text from left to right</p>
<p dir="rtl">Text from right to left</p>
<p dir="auto">שלום, this sentence starts in Hebrew</p>Definition and usage
#The dir attribute sets the writing direction. ltr is left to right (English, French), rtl is right to left (Arabic, Hebrew), and auto lets the browser guess the direction from the first strong character of the content.
Direction affects not only the text but also the layout: in rtl, inline elements, lists and table columns flow from the right. That is why pages in right-to-left languages set dir="rtl" on the <html> element.
The auto value is useful for user-generated content whose language you do not know in advance, such as comments or usernames.
Syntax
#<element dir="ltr | rtl | auto">…</element>Values
#ltr
Left to right. The default direction for languages such as English.rtl
Right to left, for example for Arabic and Hebrew.auto
The browser determines the direction from the element’s content.
Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- For single inserts of unknown direction (for example usernames), use
<bdi>. - In CSS, use logical properties such as
margin-inline-startinstead ofmargin-left. They work correctly in both directions.
Related entries
#Spotted a mistake or missing an example? Write to us.