Skip to content

Use a content utility with before/after variants adds the content CSS property twice #18178

Closed

Description

@rozsazoltan

What version of Tailwind CSS are you using?

v4.1.8

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

Tailwind Play

Reproduction URL

https://play.tailwindcss.com/rO3bQlDyWh

Describe your issue

The content utility adds the content property. Since the content property is required to display ::before and ::after pseudo-elements, the CSS rule content: var(--tw-content); is automatically added to the class when using before or after variants.

However, if I apply a custom content utility together with the before or after variants, the content property is added to the class twice:

/* Generated Utilities */

.content-\[\'custom\'\] {
  --tw-content: 'custom';
  content: var(--tw-content);
}
.before\:content-\[\'custom\'\] {
  &::before {
    content: var(--tw-content);
    --tw-content: 'custom';
    content: var(--tw-content);
  }
}
.after\:content-\[\'custom\'\] {
  &::after {
    content: var(--tw-content);
    --tw-content: 'custom';
    content: var(--tw-content);
  }
}

In this case, it would be sufficient to keep only one of them.

/* Expected Generated Utilities */

.content-\[\'custom\'\] {
  --tw-content: 'custom';
  content: var(--tw-content);
}
.before\:content-\[\'custom\'\] {
  &::before {
    --tw-content: 'custom';
    content: var(--tw-content);
  }
}
.after\:content-\[\'custom\'\] {
  &::after {
    --tw-content: 'custom';
    content: var(--tw-content);
  }
}

Activity

  1. rozsazoltan commented on May 29, 2025

    @rozsazoltan
    ContributorAuthor

    I haven't checked, but I assume minification takes care of the duplication? Either way, the reason for the duplication is understandable, and it's not a big deal - I just wanted to leave a note.

  2. thecrypticace commented on May 29, 2025

    @thecrypticace
    Contributor

    Lightning CSS doesn't appear to remove the duplicate content property. There being an extra one isn't really a big deal but maybe this is a micro optimization we can make when doing our internal optimize pass.

  3. added a commit that references this issue on Aug 29, 2025
    5e2a160
  4. thecrypticace commented on Aug 29, 2025

    @thecrypticace
    Contributor

    I've implemented an optimization that should clean this up. Will be in the next release. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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