Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

A custom Tailwind width or height class has no effect

Errorw-[350px] has no effect in the browser

Short answer

Tailwind only creates CSS for class names it finds as complete strings in files it scans. A custom size fails when the syntax is wrong, when the class is built from parts at runtime, or when the file sits outside the scanned paths. Use w-[350px], write full names, and register extra paths.

  • Applies to Tailwind CSS 4, Node.js 22, React 19
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Search the generated stylesheet for the class. If it is missing from the CSS, Tailwind never saw it. If it is there, another rule is overriding it.

    grep -rl "350px" dist build .next 2>/dev/null
  2. 2Match what you see, then jump to its fix

    1. 1The class looks like w-350px or w-350, and nothing is generated.The class name is wrong for a custom valueFix
    2. 2The class is written like `w-[${size}px]` or `w-${n}` in code.The class name is built from parts at runtimeFix
    3. 3Classes work in some files and not in a shared library or a folder listed in .gitignore.The file with the class is outside what Tailwind scansFix

What does the error look like?

  • w-[350px] has no effect in the browser
  • The same width written in plain CSS works

Cause 1 of 3

The class name is wrong for a custom value

1Check

The w-<number> form multiplies the spacing scale, so w-350 does not mean 350px. A fixed custom size needs square brackets.

grep -rn "w-350" src/

2Fix

Use the arbitrary value form. For a CSS variable use the parentheses form in Tailwind 4.

<div className="w-[350px] h-[200px]" />
<div className="w-(--my-width)" />

3Verify

Reload and inspect the element: width should be 350px.

npm run dev

Confirmed by tailwindcss.com

Did this fix it?

Cause 2 of 3

The class name is built from parts at runtime

1Check

Tailwind reads source files as plain text and cannot see a name assembled from variables.

grep -rn "w-\${" src/

2Fix

Write complete class names and choose between them, or map a prop to full names.

const widths = {
  small: "w-[200px]",
  large: "w-[400px]",
};
return <div className={widths[size]} />;

3Verify

Render each variant and check that the width changes.

npm run dev

Confirmed by tailwindcss.com

Did this fix it?

Cause 3 of 3

The file with the class is outside what Tailwind scans

1Check

Tailwind 4 scans the project but skips files in .gitignore, node_modules and binary files.

cat .gitignore

2Fix

Register the extra path in your CSS with @source.

@import "tailwindcss";
@source "../node_modules/@acmecorp/ui-lib";

3Verify

Restart the dev server and check that the class now has an effect.

npm run dev

Confirmed by tailwindcss.com

Did this fix it?

How do I stop it coming back?

  • Keep full class names in the source, even when you choose between them with a condition.
  • Use w-[value] for one-off sizes, and add a theme variable when a size repeats.
  • Register library paths with @source when you share components between packages.

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:

Related fixes

Web 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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.