A Tailwind class with square brackets produces no CSS or the wrong CSS
grid-cols-[1fr 500px 2fr] has no effectShort answer
Tailwind turns a class in square brackets into CSS only when the whole string is in a scanned file and the value is valid. A space must be written as an underscore, and a CSS variable needs a type hint so Tailwind knows if it is a size or a colour. Strings built at runtime are never found.
Fix it fast
1Find out which cause you have
Open the browser dev tools on the element and check whether the generated class exists in the stylesheet. No rule for your class means Tailwind did not generate it; a rule with the wrong property means it guessed wrongly.
grep -rn "\\[" src/ --include=*.jsx --include=*.tsx | grep className | head2Match what you see, then jump to its fix
- 1
The class contains a space and no CSS appears for it.A space was typed inside the bracketsFix - 2
A variable-based text class does not give the property you meant.A CSS variable is ambiguous, so Tailwind picks the wrong utility or noneFix - 3
w-[${width}px] works in the code but no CSS is generated.The class name is built from a variable, so it never appears in the sourceFix
- 1
What does the error look like?
grid-cols-[1fr 500px 2fr] has no effectA class built on a CSS variable, such as text-[var(--size)], generates the wrong property or nothing
Cause 1 of 3
A space was typed inside the brackets
1Check
A class name cannot contain a space, so the browser sees two classes. Tailwind's own rule is to write an underscore, and it converts it to a space at build time.
grep -rn "grid-cols-\[" src/2Fix
Replace each space with an underscore.
<div className="grid grid-cols-[1fr_500px_2fr]">3Verify
The grid shows three columns with the sizes you gave.
npm run devConfirmed by tailwindcss.com
Cause 2 of 3
A CSS variable is ambiguous, so Tailwind picks the wrong utility or none
1Check
Tailwind infers the property from the value. A variable could be a size or a colour, so the docs say to add a type before it.
grep -rn "text-\[var\|text-(--" src/2Fix
In Tailwind 4, use the shorthand with a type hint.
<p className="text-(length:--my-var)">Size</p>
<p className="text-(color:--my-var)">Colour</p>3Verify
Dev tools shows font-size for the first and color for the second.
npm run devConfirmed by tailwindcss.com
Cause 3 of 3
The class name is built from a variable, so it never appears in the source
1Check
Tailwind scans files as plain text and cannot interpret string interpolation. The class must exist as a complete string.
grep -rn 'w-\[\${' src/2Fix
Use a complete class for each choice.
const widths = { sm: 'w-[240px]', lg: 'w-[480px]' };
<div className={widths[size]} />3Verify
Both classes appear in the generated stylesheet.
npm run buildConfirmed by tailwindcss.com
How do I stop it coming back?
- Write arbitrary values as complete strings and use underscores for spaces.
- Add length: or color: to a variable shorthand when the value could be both.
- Use a mapping object for choices; never concatenate class names.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
A custom Tailwind width or height class has no effect
The same width written in plain CSS works
Tailwind only creates CSS for class names it finds as complete strings in files it scans.
3 causes, each with a fixWeb apps
There is no tailwind.config.js after installing Tailwind 4 and HeroUI in Next.js
HeroUI components render unstyled
Nothing is broken: Tailwind CSS 4 is configured in CSS and no longer creates tailwind.config.js.
3 causes, each with a fixWeb apps
Hydration failed after adding next-themes dark mode
Console reports a server and client mismatch on the html element
next-themes changes the html element and knows the theme only in the browser, so server HTML and client HTML differ.
3 causes, each with a fixWeb apps
TypeScript marks className as an error on React Native components
Property 'className' does not exist on type
React Native components have no className prop in their own types.
3 causes, each with a fixWeb apps
A shadcn/ui Dialog stays open after the form is submitted
Form submits and the data saves, but the modal remains on screen
A shadcn Dialog is a Radix dialog.
3 causes, each with a fixWeb apps
shadcn/ui setup fails in a Vite React project using Tailwind v4
Imports from @/components/ui do not resolve in the editor or the build
shadcn init needs three things in a Vite project: Tailwind v4 installed with the @tailwindcss/vite plugin and a single @import "tailwindcss" line in your CSS, the @/* path alias in both tsconfig.json and tsconfig.app.json, and the same alias in vite.config.ts, with @types/node installed so path resolves.
4 causes, each with a fix