Skip to content

CSS logical properties require dir attribute #487

@bjorn2404

Description

@bjorn2404

Describe the bug

When using CSS logical properties like margin-inline-start, the PostCSS pipeline transforms them into [dir=ltr] / [dir=rtl] attribute selectors. However, WordPress only outputs dir="rtl" for RTL sites - it never outputs dir="ltr" for LTR sites. This causes logical property styles to silently fail on standard WordPress installations.

  • postcss-preset-env includes postcss-dir-pseudo-class which transforms :dir() pseudo-classes into [dir] attribute selectors
  • postcss-logical uses this for bidirectional output
  • The postcss-dir-pseudo-class README explicitly states it requires a [dir] attribute in HTML
  • WordPress's language_attributes() function only outputs dir="rtl" for RTL sites, never dir="ltr" for LTR

Steps to Reproduce

  1. Create a WordPress project using 10up-toolkit
  2. Write CSS using logical properties:
.sidebar > * {
    margin-inline-start: auto;
}
  1. Build the project
  2. View compiled CSS - it outputs:
dir=[ltr] .sidebar > * {
    margin-left: auto;
}
[dir=rtl] .sidebar > * {
    margin-right: auto;
}
  1. View WordPress page source - HTML element has no dir attribute:
    <html lang="en-US">
  2. The [dir=ltr] selector never matches, style doesn't apply

Screenshots, screen recording, code snippet

Image

Environment information

  • Node.js: 20.11.0
  • Device: MacBook

WordPress information

  • 10up-toolkit: 6.5.1
  • WordPress: 6.9.4
  • postcss-preset-env: 9.6.0
  • postcss-dir-pseudo-class: 8.0.1

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions