Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Nossos voluntários ainda não traduziram este artigo para o Português (do Brasil) . Junte-se a nós e ajude a fazer o trabalho!

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.

Syntax

var currentWritingDirection = elementNodeReference.dir;
elementNodeReference.dir = newWritingDirection;
  • currentWritingDirection is a string variable representing the text writing direction of the current element.
  • newWritingDirection is a string variable representing the text writing direction value.

Possible values for dir are ltr, for left-to-right, rtl, for right-to-left, and auto for specifying that the direction of the element must be determined based on the contents of the element.

Example

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

Specification

Specification Status Comment
WHATWG HTML Living Standard
The definition of 'dir' in that specification.
Living Standard No change from Document Object Model (DOM) Level 2 HTML Specification.
Document Object Model (DOM) Level 2 HTML Specification
The definition of 'dir' in that specification.
Recommendation No change from Document Object Model (DOM) Level 1 Specification.
Document Object Model (DOM) Level 1 Specification
The definition of 'dir' in that specification.
Recommendation Initial definition.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes) [1] (Yes) (Yes) (Yes)
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) [1] (Yes) (Yes) (Yes)

[1] Prior to Firefox 7, it was possible for the returned value to not be all lower-case. Starting in Firefox 7, the returned strings are always all lower-case, as required by the specification.

See also

Etiquetas do documento e colaboradores

 Última atualização por: Jeremie,