Skip to content

Pseudo-element selectors in styles.**.css property no longer work in 6.6 compared to 6.5 #63932

@wongjn

Description

@wongjn

Description

With the CSS specificity change in WordPress 6.6, most rules are now wrapped in :root :where(). However, pseudo-elements like ::before and ::after cannot be wrapped in :where().

This means theme.json like this:

{
  "$schema": "https://schemas.wp.org/wp/6.6/theme.json",
  "version": 3,
  "styles": {
    "elements": {
      "h1": {
        "css": "&::before { content: 'Foo' }"
      }
    }
  }
}

Produces:

:root :where(h1::before) {
  content: 'Foo';
}

Which is invalid CSS and causes the CSS rule to no longer apply.

Step-by-step reproduction instructions

  1. Install fresh WordPress.
  2. Add an entry for core/heading in styles.blocks in twentytwentyfour/theme.json:
     },
    +"core/heading": {
    +  "css": "&::before { content: 'Foo' }"
    +},
     "core/image": {
  3. See the invalid inline CSS gets added to the webpage:
    :root :where(.wp-block-heading::before ){content: 'Foo'}
    Compare this to the equivalent in 6.5.5:
    .wp-block-heading::before {content: 'Foo'}
    Which is valid CSS.

Screenshots, screen recording, code snippet

No response

Environment info

  • WordPress 6.6.1
  • Twenty Twenty-Four 1.2

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Metadata

Metadata

Labels

Global StylesAnything related to the broader Global Styles efforts, including Styles Engine and theme.json[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions