Skip to content

A utility's nested rule under a pseudo-element variant is written as ::selection > * and dropped with a warning #20571

Closed

Description

@mauritskorse

What version of Tailwind CSS are you using?
v4.3.3 (tailwindcss, @tailwindcss/vite 4.3.3, Vite 8.3.2)

What build tool (or framework if it abstracts the build tool) are you using?
Vite 8.3.2 with @tailwindcss/vite

What version of Node.js are you using?
v22.14.0

What browser are you using?
n/a (build output)

What operating system are you using?
Linux (WSL2)

Reproduction URL:
https://play.tailwindcss.com/fj2ehk4puO

Describe your issue

A custom utility with a nested child rule:

@utility bg-* {
  & > * {
    --nearest-bg: --value(--color-*);
  }
}

used under a pseudo-element variant, such as selection:bg-red-500 (also backdrop:, before:, after:, marker:), makes the build print:

Found 1 warning while optimizing generated CSS:

Issue #1:
  .selection\:bg-red-500 ::selection > * {
                                     ^-- Pseudo-elements like '::before' or '::after' can't be followed by selectors like 'Delim('>')'

The variant is applied to every nested rule of the matched utility. The nesting is then flattened by pasting the parent selector in for &, which gives .x::selection > *. Under CSS Nesting, & cannot represent a pseudo-element, so that rule matches nothing and could be dropped quietly. Today lightningcss drops it with the warning above. For before:/after: the rule is dropped silently and an empty .after\:bg-white:after{content:var(--tw-content)} remains. For marker: the output keeps ::-webkit-details-marker>* with no warning.

A utility cannot opt out on its side: it never sees which variants the class carries, and @variant inside it cannot name a negated pseudo-element variant.

Expected: a nested rule whose parent selector ends in a pseudo-element is dropped while flattening, with no warning, as Tailwind already does silently for its own selection:space-x-4 (which ships a dead :where() rule).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions