Skip to content

Bug: Invalid CSS var(--prefix-*) with literal asterisk when arbitrary values share variable prefix #19992

@thanhquangqb95

Description

@thanhquangqb95

Description

When two or more arbitrary value utility classes reference CSS custom properties that share a common prefix (e.g., --sidebar-width and --sidebar-collapsed-width), Tailwind CSS v4.2.4 generates a single collapsed utility containing var(--sidebar-*) with a literal * character. This is not valid CSS and causes Lightning CSS to throw a parse error, crashing the dev server.

Reproduction

  1. Define CSS variables with a shared prefix:
    :root {
      --sidebar-width: 240px;
      --sidebar-collapsed-width: 80px;
    }
  2. Use both as Tailwind arbitrary values in a template:
    <div class="md:ml-[var(--sidebar-width)]">Full sidebar</div>
    <div class="md:ml-[var(--sidebar-collapsed-width)]">Collapsed sidebar</div>
  3. Run pnpm dev with @tailwindcss/postcss

Result: Lightning CSS parse error, page returns HTTP 500.

Expected Behavior

Two separate CSS rules generated:

.md\:ml-\[var\(--sidebar-width\)\] {
  @media (width >= 48rem) {
    margin-left: var(--sidebar-width);
  }
}
.md\:ml-\[var\(--sidebar-collapsed-width\)\] {
  @media (width >= 48rem) {
    margin-left: var(--sidebar-collapsed-width);
  }
}

Actual Behavior

A third "collapsed" utility is generated with a literal * that is not valid CSS:

.md\:ml-\[var\(--sidebar-\*\)\] {
  @media (width >= 48rem) {
    margin-left: var(--sidebar-*);  /* ← INVALID: Delim('*') */
  }
}

Error:

Parsing CSS source code failed
Unexpected token Delim('*')

This appears before the individual utilities in the compiled output (~line 5520), blocking the entire CSS compilation.

Environment

  • Tailwind CSS: v4.2.4
  • Framework: Next.js 16.2.4 (Turbopack default)
  • PostCSS: @tailwindcss/postcss
  • Parser: Lightning CSS
  • OS: Windows 11

Workaround

Use @utility directive to define named utilities, bypassing arbitrary value candidate generation:

@utility ml-sidebar-width {
  margin-left: var(--sidebar-width);
}
@utility ml-sidebar-collapsed {
  margin-left: var(--sidebar-collapsed-width);
}

Then use md:ml-sidebar-width and md:ml-sidebar-collapsed in templates.

Notes

  • This does NOT happen when only one of the two classes is present — it requires both classes sharing the same utility (ml-) and CSS variable prefix (--sidebar-).
  • The same issue occurs with w-[var(--sidebar-width)] / w-[var(--sidebar-collapsed-width)].
  • Complex expressions like calc(var(--sidebar-width) + 10px) wrapped in functions do NOT trigger this — only bare var(--prefix-X) references.
  • Related: [v4] Namespace override syntax is not valid CSS #15602 (acknowledges * is not valid CSS in namespace context), but that issue covers theme-defined namespaces, not arbitrary value collapse in the normal build pipeline.
  • I searched open/closed issues for "namespace grouping", "var(--", "wildcard custom property", "arbitrary value collapse", "Delim('')" — no existing report found.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions