Skip to content

:dir() improved support #177

@brandonmcconnell

Description

@brandonmcconnell

Description

"The :dir() pseudo-class in CSS allows elements to be selected based on the direction of the language, as determined in the HTML markup. There are really only two directions language can flow in a document, which are left-to-right and right-to-left. Think of this as a way to style elements that are distinguished by different language directionality."
@geoffgraham (via CSS Tricks)

I couldn't have explained it better, myself. Thanks, Geoff 🙏🏼

Rationale

:dir() support is important to the effort of internationalization. This pseudo-class has been a long time coming and has been a topic of discussion for a while now as well:

Formal (docs-style)

Informal

Directionality can currently be set in two primary ways— setting the HTML dir attribute to either ltr or rtl, or setting the direction property in CSS to either of those same values.

Elements explicitly setting dir="rtl" (or similar) can already be targeted with CSS using an attribute selector. However, this is usually an edge case, as that property is usually set once on a document, and does not necessarily apply that same directionality to all elements on the page.

:dir() is the solution here:

  • matches [dir="rtl"] (or similar)
  • matches direction: rtl (or similar)
  • matches directionality that is either inherited or purposefully not inherited from a parent element

Specification

https://w3c.github.io/csswg-drafts/selectors-4/#the-dir-pseudo

Tests

More tests will likely be needed for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions