Skip to content

Tailwind Vite Plugin does not properly handle variables in class names, but Tailwind Play CDN does. #18105

@fornof

Description

@fornof

What version of Tailwind CSS are you using?
v4.1.7

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

What version of Node.js are you using?
node 23.11.0

What browser are you using?
chrome

What operating system are you using?
WSL ubuntu in windows

Reproduction URL

export function ListGrid(props: any) {
    const num = 5
    const size = `grid-cols-${num}`

    return (
            <div className={`grid ${size} gap-0`}>
                <div>a</div>
                 <div>b</div>
                <div>c</div>
                <div>d</div>
                <div>e</div>
                <div>f</div>
                <div>g</div>
                <div>h</div>
                
            </div>
        
    )
}

A Tailwind Play link or public GitHub repo that includes a minimal reproduction of the bug. Please do not link to your actual project, what we need instead is a minimal reproduction in a fresh project without any unnecessary code. This means it doesn't matter if your real project is private/confidential, since we want a link to a separate, isolated reproduction anyways.

A reproduction is required when filing an issue — any issue opened without a reproduction will be closed and you'll be asked to create a new issue that includes a reproduction. We're a small team and we can't keep up with the volume of issues we receive if we need to reproduce each issue from scratch ourselves.

Describe your issue

This runs perfectly in the cdn version with script, but with vite plugin, it doesn't render the grid columns at all. just straight down, even though it says the class="grid grid-cols-5 gap0" , it does not have 5 columns (just 1), I tried multiple things like

safelist: [
{
pattern: /grid-cols-./,
}
],
etc. When I tried to show an example to my coworker of it not working , everything was working perfectly in the online playgrounds. So, vite and the plugin for vite is the culprit, possibly due to how it renders in conjunction with react. I'm using react 19.1.0

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