W3cubDocs

/Web APIs

HTMLElement: dir property

The HTMLElement.dir property gets or sets the text writing directionality of the content of the current element.

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.

An image can have its dir property set to "rtl" in which case the HTML attributes title and alt will be formatted and defined as "rtl".

When a table has its dir set to "rtl", the column order is arranged from right to left.

When an element has its dir set to "auto", the direction of the element is determined based on its first strong directionality character, or default to the directionality of its parent element.

Note: Browsers might allow users to change the directionality of <input> and <textarea>s in order to assist with authoring content. Chrome and Safari provide a directionality option in the contextual menu of input fields while pre-Chromium Edge uses the key combinations Ctrl + Left Shift and Ctrl + Right Shift. Firefox uses Ctrl/Cmd + Shift + X but does NOT update the dir attribute value.

Value

One of the following:

  • ltr, for left-to-right;
  • rtl, for right-to-left;
  • auto for specifying that the direction of the element must be determined based on the contents of the element.

Examples

js

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

Specifications

Specification
HTML Standard
# dom-dir

Browser compatibility

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

See also

© 2005–2023 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