Maaz Zindani

Loading the index…

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

ESLint flags valid class names with tailwindcss/no-custom-classname

Your error

Classname 'btn-primary' is not a Tailwind CSS class1 more line it can show

Fix it fast

Most common cause, 1 of 3

The class comes from your own CSS or a UI library

List those names in the rule's whitelist option, which takes exact names or regular expressions.

Fix
// eslint.config.mjs
rules: {
  "tailwindcss/no-custom-classname": [
    "warn",
    { whitelist: ["btn-primary", "swiper-.*"] },
  ],
},
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

Classname 'x' is not a Tailwind CSS class comes from the tailwindcss/no-custom-classname ESLint rule. It flags any class missing from the Tailwind design system it loaded. With Tailwind v4, set cssConfigPath to the CSS file holding @import "tailwindcss" and your @theme, whitelist classes from your own CSS or libraries, and use plugin 4.x. Applies to eslint-plugin-tailwindcss 4.4.

  • Applies to eslint-plugin-tailwindcss 4.4.0, Tailwind CSS 4.3.5, ESLint 10.15 (the plugin supports ESLint 9 and 10)
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Print the installed plugin and Tailwind versions, then look for cssConfigPath in the ESLint config. A 3.x plugin with Tailwind 4 is cause 3; no cssConfigPath, or one that names a file without your @theme, is cause 2; a correct setup that still flags your own class names is cause 1.

Run this first
npm ls eslint-plugin-tailwindcss tailwindcss
grep -rn "cssConfigPath" eslint.config.*

Then find the line you see in this list and open its fix:

  1. 1The class comes from your own CSS or a UI libraryOnly names such as btn-primary or swiper-slide are flagged, while normal utilities like flex and p-4 pass
  2. 2cssConfigPath is missing or points to the wrong CSS fileClasses from your @theme block, such as bg-brand-500, are flagged, while stock utilities pass
  3. 3The plugin's major version does not match Tailwind'snpm ls shows eslint-plugin-tailwindcss 3.x next to tailwindcss 4.x, or plugin 4.x in a project still on Tailwind 3

What does the error look like?

  • Classname 'btn-primary' is not a Tailwind CSS class
  • Classname 'bg-brand-500' is not a Tailwind CSS class!

Cause 1 of 3

The class comes from your own CSS or a UI library

You seeOnly names such as btn-primary or swiper-slide are flagged, while normal utilities like flex and p-4 pass

Check

The no-custom-classname rule exists to report every class that Tailwind does not define, so a hand-written CSS class or a library's class name gets the warning even though it works in the browser. The rule is behaving as designed here.

Check
npx eslint src/components/Card.tsx

Fix

List those names in the rule's whitelist option, which takes exact names or regular expressions. If a helper class belongs to your design system, define it with @utility in the CSS file that cssConfigPath names, so it becomes a real utility instead of an exception.

Fix
// eslint.config.mjs
rules: {
  "tailwindcss/no-custom-classname": [
    "warn",
    { whitelist: ["btn-primary", "swiper-.*"] },
  ],
},

Verify

ESLint no longer reports the whitelisted names, and a typo such as flexx is still caught.

Verify
npx eslint src

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 2 of 3

cssConfigPath is missing or points to the wrong CSS file

You seeClasses from your @theme block, such as bg-brand-500, are flagged, while stock utilities pass

Check

Version 4 of the plugin builds its list of valid classes from one CSS file, the cssConfigPath setting, and falls back to src/style.css when the setting is absent. Colors and spacing you declared with @theme in another file are unknown to it, so their utilities look custom.

Check
grep -rln '@import "tailwindcss"' src app resources 2>/dev/null

Fix

Set cssConfigPath in the shared tailwindcss settings to the CSS entry that imports Tailwind and holds your @theme. The plugin tries to turn a relative path into an absolute one, so a path from the project root works.

Fix
// eslint.config.mjs
import tailwind from "eslint-plugin-tailwindcss";
import { defineConfig } from "eslint/config";

export default defineConfig([
  tailwind.configs["flat/recommended"],
  {
    settings: {
      tailwindcss: { cssConfigPath: "./src/app/globals.css" },
    },
  },
]);

Verify

Run ESLint again; your theme classes pass and only real unknown names remain.

Verify
npx eslint src

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 3 of 3

The plugin's major version does not match Tailwind's

You seenpm ls shows eslint-plugin-tailwindcss 3.x next to tailwindcss 4.x, or plugin 4.x in a project still on Tailwind 3

Check

The 3.x line reads a JavaScript tailwind.config.js through its config setting, and its README only offers partial Tailwind 4 support on a beta channel. Plugin 4.x declares a peer dependency on tailwindcss ^4.0.0 and reads the theme from CSS, so each line only fits its own Tailwind major.

Check
npm view eslint-plugin-tailwindcss@latest peerDependencies

Fix

On Tailwind 4, install the current plugin and add cssConfigPath. A project that stays on Tailwind 3 keeps the 3.x plugin with its tailwind.config.js setup.

Fix
# Tailwind 4 project
npm i -D eslint-plugin-tailwindcss@latest
# Tailwind 3 project
npm i -D eslint-plugin-tailwindcss@3

Verify

npm ls shows matching majors, and the flagged list shrinks to names that are not utilities.

Verify
npm ls eslint-plugin-tailwindcss tailwindcss

Confirmed by raw.githubusercontent.com

Did this fix it?

How do I stop it coming back?

  • Keep cssConfigPath in the ESLint config next to the path of the CSS entry, and update both in the same commit if the file moves.
  • Upgrade eslint-plugin-tailwindcss in the same pull request as a Tailwind major upgrade.
  • Give your own component classes a shared prefix so one whitelist pattern covers all of them.

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?

Next step

Want this handled for good?

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