CSS :dir() Pseudo-Class

Beginner
2 examples
Updated: Nov 2026

Definition and Usage

The :dir() pseudo-class matches elements by their computed directionality. Use :dir(rtl) or :dir(ltr) to adjust icons, margins, and alignment.

CSS Syntax

syntax.css
:dir(rtl) .icon {
  transform: scaleX(-1);
}

Key Uses

PatternPurposeTry it
:dir(ltr)Left-to-right directionalityTry it
:dir(rtl)Right-to-left directionalityTry it

CSS Examples

Mirror icons in RTL

example.css
:dir(rtl) .chevron {
  transform: scaleX(-1);
}
Try It Yourself

Browser Support

:dir() is a CSS selector.

✓ Selectors

:dir()

Supported in modern browsers.

94% Modern browsers
Google Chrome Recent
Full support
Mozilla Firefox Recent
Full support
Apple Safari Recent
Full support
Microsoft Edge Recent
Full support
:dir() Modern support

Bottom line: Safe for modern sites. Keep readable defaults without the selector.

Frequently Asked Questions

No. :dir() uses computed directionality, which can come from inheritance or language, not only the dir attribute.
ltr and rtl.
No. It only selects elements. Use direction or HTML dir to set direction.
Bilingual UI chrome, mirrored arrows, and logical spacing tweaks.
Supported in modern browsers; prefer logical properties when possible.

Next: :defined

Continue with :defined.

:defined →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

2 people found this page helpful