Skip to content

Canonicalization rewrites [&_::pseudo-element]:* to **:[::pseudo-element]:*, which is a syntax error #20549

Closed

Description

@abrahamguo

What version of Tailwind CSS are you using?

v4.3.3 (also reproduces on 0.0.0-insiders.fa81d69)

What build tool (or framework if it abstracts the build tool) are you using?

@tailwindcss/cli 4.3.3 (tailwindcss canonicalize)

What version of Node.js are you using?

v26.10.0

What browser are you using?

Chrome

What operating system are you using?

macOS

Reproduction URL

https://play.tailwindcss.com/9dPXQ2weIo

Describe your issue

npx @tailwindcss/[email protected] canonicalize '[&_::before]:text-red-500'
# **:[::before]:text-red-500

The two classes are not equivalent:

/* [&_::before]:text-red-500 */
.\[\&_\:\:before\]\:text-red-500 ::before { … }

/* **:[::before]:text-red-500 */
:is(.\*\*\:\[\:\:before\]\:text-red-500 *):is(::before) { … }

[::before] has no &, so it compiles to &:is(::before). Pseudo-elements aren't valid inside :is(), so it's a syntax error. In the Play link, the first dot is red and the second (the canonical form) stays black.

The same thing happens for every pseudo-element without an equivalent named variant, e.g. ::before, ::marker, ::-webkit-scrollbar and ::-webkit-search-cancel-button. It also happens with the child combinator: [&>::before] → *:[::before], which compiles to :is(.… > *):is(::before). Other cases come out right:

  • Pseudo-classes are fine: [&_:hover] → **:[:hover] compiles to :is(.… *):is(:hover), which is equivalent.
  • With a named variant it's fine: [&_::placeholder] → **:placeholder.

Expected: keep the &, i.e. **:[&::before]:text-red-500, which compiles to :is(.… *)::before, or leave the class unchanged. (**:[&::before]:text-red-500 is already treated as canonical.)

Cause: This was introduced in a41add9 (#19178, first released in v4.1.16). That commit widened the [&_X] / [&>X] rewrites from attribute selectors to any X starting with :. It also added a fallback that emits **:[X] / *:[X] when X has no named variant. That's correct for pseudo-classes, which are the only cases its tests cover (:first-child, :--custom). But ::before also starts with :, and the fallback drops the & that a pseudo-element needs.

Activity

  1. changed the title [-]Canonicalization rewrites `[&_::pseudo-element]:*` to `**:[::pseudo-element]:*`, which matches nothing[/-] [+]Canonicalization rewrites `[&_::pseudo-element]:*` to `**:[::pseudo-element]:*`, which is a syntax error[/+] on Oct 6, 2026
  2. wongjn commented on Oct 7, 2026

    @wongjn
    Collaborator

    ::before has a named variant, so really, the canonical form should be **:before

  3. abrahamguo commented on Oct 7, 2026

    @abrahamguo
    Author

    @wongjn Technically no; as &::before doesn't set content whereas before: does.

  4. wongjn commented on Oct 7, 2026

    @wongjn
    Collaborator

    Ah yes, interesting distinction!

  5. pricklymusic commented on Oct 8, 2026

    @pricklymusic

    We need to update the canonicalization logic to detect pseudo-elements and prevent them from being extracted into a separate `:is

  6. abrahamguo commented on Oct 10, 2026

    @abrahamguo
    Author

    @pricklymusic Yes, that's exactly what @lazerg's PR does!

  7. added a commit that references this issue on Oct 12, 2026
    392fb6d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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