W3cubDocs

/Web APIs

HTMLElement: dir property

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨July 2015⁩.

The HTMLElement.dir property indicates the text writing directionality of the content of the current element. It reflects the element's dir attribute.

Note that if the dir attribute is unspecified, the element itself may still inherit directionality from its parent. However, that inherited directionality is not reflected by this property's value.

The text writing directionality of an element is which direction that text goes (for support of different language systems). Arabic languages and Hebrew are typical languages using the RTL directionality.

Value

One of the following:

"ltr"

Left-to-right writing direction.

"rtl"

Right-to-left writing direction.

"auto"

The direction of the element must be determined based on the contents of the element.

""

The default value; the directionality is inherited from the parent element.

Examples

const para = document.getElementById("para1");
para.dir = "rtl";
// change the text direction on a paragraph identified as "para1"

Specifications

Specification
HTML>
# dom-dir>

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Opera Safari Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet WebView Android WebView on iOS
dir 1 12 1 ≤12.1 3 18 4 ≤12.1 1 1.0 4.4 1

See also

© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dir