Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. HTML
  3. Reference
  4. Global attributes
  5. dir

HTML dir global attribute

Thedirglobal attribute is anenumerated attribute that indicates the directionality of the element's text.

Try it

<p dir="rtl">  This paragraph is in English but incorrectly goes right to left.</p><p dir="ltr">This paragraph is in English and correctly goes left to right.</p><hr /><p>هذه الفقرة باللغة العربية ولكن بشكل خاطئ من اليسار إلى اليمين.</p><p dir="auto">  هذه الفقرة باللغة العربية ، لذا يجب الانتقال من اليمين إلى اليسار.</p>

It can have the following values:

  • ltr, which meansleft to right and is to be used for languages that are written from the left to the right (like English);
  • rtl, which meansright to left and is to be used for languages that are written from the right to the left (like Arabic);
  • auto, which lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element.

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

If unspecified, the value isinherited from the parent element.

This attribute can be overridden by the CSS propertiesdirection andunicode-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 nodir attribute, it will inherit thedir value set on itsparent node, which in turn may inherit it from its parent, and so on.

Usage notes

An image can have itsdir property set to"rtl" in which case the HTML attributestitle andalt will be formatted and defined as"rtl".

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

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

This attribute isnot inherited by the<bdi> element. If not set, its value isauto.

Browsers might allow users to change the directionality of<input> and<textarea> elements in order to assist with authoring content.Chrome and Safari provide a directionality option in the contextual menu of input fields.Firefox usesCtrl (Windows)/Cmd (macOS) +Shift +X inside a<textarea> to toggle text direction.These features toggle thedir attribute value betweenltr andrtl.

Specifications

Specification
HTML
# the-dir-attribute

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp