dir property CSS Reference

Definition and Usage

The :dir CSS pseudo-class matches elements based on the directionality of the text contained in it. In HTML, the direction is determined by the dir attribute. For other document types there may be other document methods for determining the language.

Note that the usage of the pseudo-class :dir() is not equivalent of using the [dir=…] attribute selectors. The latter matches a value of the dir and doesn't match when no attribute is set, even if in that case the element inherits the value of its parent; similarly [dir=rtl] or [dir=ltr] won't match the auto value that can be used on the dir attribute. In the opposite, :dir() will match the value calculated by the UA, being inherited or the auto value.

Also :dir() considers only the semantic value of the directionality, the one defined in the document, most of the time in HTML. It won't consider styling directionality, the one set by CSS properties like direction which are purely stylistic.


element:dir(directionality) { style properties } where directionality is ltr or rtl.


<div dir="rtl">
  <div dir="ltr">test2
    <div dir="auto">עִבְרִית</div>
In this example :dir(rtl) will match the top level div, span containing test1, and the div with the hebrew characters. :dir(ltr) will match the div containing test2.


Desktop browsers

FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic supportNot supported17.0 (17)
18.0 (18) -moz
Not supportedNot supportedNot supported

Mobile browsers

FeatureAndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic supportNot supported17.0 (17)
18.0 (18) -moz
Not supportedNot supportedNot supported

Relative articles