Skip to content

TailwindCSS Prefixing Breaks Custom Theme Variables in Utility Classes #18687

@rashadmehtab

Description

@rashadmehtab

What version of Tailwind CSS are you using?

v4.1.11

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

webpack

What version of Node.js are you using?

v20.18.3

What browser are you using?

Chrome

What operating system are you using?

Windows

Reproduction URL

https://play.tailwindcss.com/be7vc5mYw8?file=css

Describe your issue

When using @import "tailwindcss" prefix(tw);, custom theme variables (e.g., --btn-color) inside a utility class (e.g., .btn) don't resolve correctly. The background color doesn't apply, and using var(--btn-color) breaks due to the prefix. The theme() function is deprecated and doesn't work in this case.

Steps to Reproduce:

  1. Define a custom theme variable --btn-color.
  2. Create a utility class that references var(--btn-color).
  3. Add prefix(tw) to the Tailwind setup.
  4. Apply the class tw:btn to an element.

Expected Behavior:

The button background should be the custom theme color --btn-color (red).

Actual Behavior:

The background color doesn't apply, and var(--btn-color) doesn’t work with the prefixed class.

Suggested Fix:

Ensure custom theme variables work correctly with prefixed class names

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