ESLint flags valid class names with tailwindcss/no-custom-classname
Fix it fast
Most common cause, 1 of 3The 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.
// eslint.config.mjs
rules: {
"tailwindcss/no-custom-classname": [
"warn",
{ whitelist: ["btn-primary", "swiper-.*"] },
],
},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.
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.
npm ls eslint-plugin-tailwindcss tailwindcss
grep -rn "cssConfigPath" eslint.config.*Then find the line you see in this list and open its fix:
- 1The class comes from your own CSS or a UI library
Only names such as btn-primary or swiper-slide are flagged, while normal utilities like flex and p-4 pass - 2cssConfigPath is missing or points to the wrong CSS file
Classes from your @theme block, such as bg-brand-500, are flagged, while stock utilities pass - 3The plugin's major version does not match Tailwind's
npm 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 classClassname '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.
npx eslint src/components/Card.tsxFix
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.
// 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.
npx eslint srcConfirmed by raw.githubusercontent.com
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.
grep -rln '@import "tailwindcss"' src app resources 2>/dev/nullFix
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.
// 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.
npx eslint srcConfirmed by raw.githubusercontent.com
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.
npm view eslint-plugin-tailwindcss@latest peerDependenciesFix
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.
# Tailwind 4 project
npm i -D eslint-plugin-tailwindcss@latest
# Tailwind 3 project
npm i -D eslint-plugin-tailwindcss@3Verify
npm ls shows matching majors, and the flagged list shrinks to names that are not utilities.
npm ls eslint-plugin-tailwindcss tailwindcssConfirmed by raw.githubusercontent.com
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.