dir – text direction (attribute)
<element dir="rtl">
The writing direction of the text of an element and its descendants. Besides the order of letters it also affects alignment, the side of the bullets and the direction in which table columns and flexbox and grid items are laid out. For pages in Arabic, Hebrew or Persian it is set on html, for text of unknown direction (input from users) to auto.
Values
ltr– left to right (default).rtl– right to left.auto– according to the first character with a strong direction in the text.
- Applies to: all elements (required on
bdo) - In JavaScript:
element.dir
Examples
Arabic text right to left and a field that recognizes the direction from its content:
<p dir="rtl" lang="ar">مرحبا بكم في مخبزنا</p> <p><input dir="auto" value="שלום" aria-label="Name"></p>
Things to watch out for
- Do not set the direction in CSS (
direction) –dirbelongs to the content and tools outside the browser respect it too. - Logical CSS properties (
margin-inline-start,text-align: start) flip by themselves, physical ones (margin-left) do not. - The
:dir(rtl)selector is supported by Chrome since 120, Firefox since 49 and Safari since 16.4 (as of October 2026).
Browser support
Works in all major browsers (web-features does not rate it for Baseline). Since version: Chrome 1, Firefox 1, Safari 4. As of October 2026 (MDN browser-compat-data).
Related:
bdi – isolated text direction
bdo – forced text direction
lang – language (attribute)
html – document root