dir - HTML: HyperText Markup Language | MDN (original) (raw)

The dir global attribute is an enumerated attribute that indicates the directionality of the element's text.

Try it

It can have the following values:

Note: The auto value should be used for data with an unknown directionality, like data coming from user input or external data.

If unspecified, the value is inherited from the parent element.

This attribute can be overridden by the CSS properties direction and unicode-bidi, if a CSS page is active and the element supports these properties.

As the directionality of the text is semantically related to its content and not to its presentation, it is recommended that web developers use this attribute instead of the related CSS properties when possible. That way, the text will display correctly even on a browser that doesn't support CSS or has the CSS deactivated.

Inheritance

If an element has no dir attribute, it will inherit the dir value set on its parent node, which in turn may inherit it from its parent, and so on.

Usage notes

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.

This attribute is mandatory for the element where it has a different semantic meaning.

This attribute is not inherited by the element. If not set, its value is auto.

Browsers might allow users to change the directionality of and s in order to assist with authoring content. Chrome and Safari provide a directionality option in the contextual menu of input fields. Firefox uses Ctrl/Cmd + Shift + X but does NOT update the dir attribute value.

Specifications

Specification
HTML Standard # the-dir-attribute

Browser compatibility

BCD tables only load in the browser

See also