CSS :dir() Pseudo-class

Definition and Usage

CSS :dir() The pseudo-class is used to match any element with a specified text direction.

  • :dir(rtl) Matches elements with a right-to-left text direction
  • :dir(ltr) Matches elements with a left-to-right text direction

Tip:In HTML, the text direction is specified through dir Property specification.

Example

Use the :dir() pseudo-class:

:dir(rtl) {
  background-color: lightgreen;
}

Try It Yourself

CSS Syntax

:dir(ltr|rtl) {
  css declarations;
}

Technical Details

Version: CSS Selectors Level 4

Browser Support

The numbers in the table specify the first browser version to fully support the pseudo-class.

Chrome Edge Firefox Safari Opera
120 120 49 16.4 106