The HTML dir attribute
Quick answer
The HTML dir attribute sets the base text direction of the element's content. It is used on any HTML element (it is a global attribute).
Overview
Syntax
<p dir="rtl">مرحبا</p>
Values
| Value |
|---|
| ltr | rtl | auto |
Example
<p dir="rtl" lang="ar">مرحبا بالعالم — Hello World</p>
Best practices
Frequently asked questions
What does the dir attribute do?
Sets the text direction of content.
How do I set right-to-left text?
Use
dir="rtl" on the element (or on <html> for the whole page).What is the difference between dir and the bdi element?
dir sets a direction; <bdi> isolates text of unknown direction so it does not disturb its surroundings.Which elements use the dir attribute?
It is an element-specific attribute, used on elements whose text direction you set, notably <bdo>.