Skip to content

Tailwind v4 arbitrary values not working: five causes and fixes

Fix broken arbitrary values in Tailwind CSS v4: parentheses for CSS variables bg-(--x), underscores for spaces, dynamic strings, type hints and @source.

Updated 3 December 2026Tested with
  • Tailwind CSS 4.3.5

When a Tailwind CSS v4 arbitrary class like w-[420px], bg-[--brand] or grid-cols-[1fr 2fr] has no effect in the browser, Tailwind either couldn't parse the syntax, didn't scan the file, or needed a type hint. Here are the five causes that account for almost every case.

Five causes and fixes

  1. Step 1: Using v3 bracket syntax for CSS variables

    In Tailwind v4, shorthand CSS variables use parentheses, not square brackets:

    css-var-fix.htmlHTML
    <!-- Wrong in v4 --><div class="bg-[--card-bg] text-[--card-fg]"> <!-- Right in v4 --><div class="bg-(--card-bg) text-(--card-fg)"><!-- Or explicit var() inside brackets --><div class="bg-[var(--card-bg)]">
  2. Step 2: Spaces inside brackets instead of underscores

    HTML splits class attributes on whitespace. Replace every space inside an arbitrary value with an underscore (_):

    spaces-fix.htmlHTML
    <!-- Wrong: browser reads two broken classes --><div class="grid grid-cols-[240px 1fr]"> <!-- Right --><div class="grid grid-cols-[240px_1fr]">
  3. Step 3: Building class names dynamically in JavaScript

    Tailwind scans source files as plain text — it never executes JavaScript. String interpolation like `w-[${width}px]` will never generate CSS. Use an inline style prop for runtime numbers, or map to complete static class strings:

    dynamic-fix.tsxTSX
    // Wrong: Tailwind cannot see the value<div className={`w-[${width}px]`} /> // Right: CSS variable or inline style<div style={{ width }} />
  4. Step 4: Ambiguous CSS variable type (color vs length)

    Utilities like text-(--x) can mean either font-size or color. Add a type hint when Tailwind picks the wrong property: text-(length:--heading-size) or text-(color:--heading-color).

  5. Step 5: File is outside Tailwind's scanned paths

    Tailwind v4 automatically ignores node_modules and paths listed in .gitignore. If a shared UI package or generated file holds your classes, point Tailwind at it with @source:

    src/styles/global.cssCSS
    @import "tailwindcss";@source "../packages/ui/src";

Questions

How do I escape a literal underscore inside an arbitrary value (like a URL)?

Prefix it with a backslash: bg-[url('https://example.com/hero\_bg.webp')]. Otherwise Tailwind turns the underscore into a space.

Why did my custom colour token not work even with @theme?

Check Tailwind v4 custom colors — the variable must start with --color- inside @theme.

Was this page helpful?

Still stuck? We answer every message ourselves. Write to us

Building with shadcn/ui and Tailwind CSS v4?

Install 188 free blocks and components with the shadcn CLI (no account), preview them in your own brand in Studio, or get all 1,570 blocks and every theme in UI Pro (€199 once).

Use it with

This page is built from UI Pro parts: the docs article block (docs-quernly) with the code, terminal, install command, steps, contents and feedback components, included in UI Pro.