How to Add a @tailwind CSS Rule for CSS Checker ?
Last Updated :
28 Apr, 2025
Tailwind CSS is basically a Utility first CSS framework for building rapid custom UI. It is a highly customizable, low-level CSS framework that gives you all of the building blocks that you need. Also, it is a cool way to write inline styling and achieve an awesome interface without writing a single line of your own CSS.
In this article, we will explore how to add a tailwind CSS rule to a CSS checker which will help developers to check their Tailwind CSS code.
The CSS checkers are the tools that help developers to help identify and fix errors in their CSS code.
There are 2 approaches to including the @tailwind CSS rule in the CSS checker:
- By implementing the custom plugins
- By implementing the manual configuration
We will explore both approaches, along with understanding their implementation through the illustration.
Approach 1: Using custom plugins
CSS checkers like Stylelint support custom plugins. By creating a custom plugin you can extend the existing checker's functionality to include Tailwind CSS rules.
Steps to Install & Configure the Stylelint:
Step 1: Create a new npm project. Run the following command to initialize a new npm project.
npm init -y
Step 2: Install Stylelint
npm install stylelint --save-dev
Step 3: Create a new JavaScript file for your custom plugin and add your custom Stylelint plugin code.
JavaScript
const stylelint = require('stylelint');
const { ruleMessages, validateOptions } = stylelint.utils;
const ruleName = 'custom-plugin/no-invalid-classes';
const messages = ruleMessages(ruleName, {
invalidClass: (className) => `Invalid class: ${className}`,
});
const plugin = stylelint.createPlugin(ruleName,
(const stylelint = require('stylelint'));
const { ruleMessages, validateOptions } = stylelint.utils;
const ruleName = 'custom-plugin/no-invalid-classes';
const messages = ruleMessages(ruleName, {
invalidClass: (className) => `Invalid class: ${className}`,
});
const plugin = stylelint.createPlugin(ruleName,
(enabled, options) => {
return (root, result) => {
// Logic to check for invalid classes goes
// here
// Example: Loop through each CSS rule and
// check for invalid classes
root.walkRules((rule) => {
const classNames = rule.selector.split('.').slice(1);
classNames.forEach((className) => {
if (className.startsWith('invalid-')) {
stylelint.utils.report({
ruleName,
result,
node: rule,
message: messages.invalidClass(className),
});
}
});
});
};
});
plugin.ruleName = ruleName;
plugin.messages = messages;
module.exports = plugin;, options) => {
return (root, result) => {
// Logic to check for invalid classes goes here
// Example: Loop through each CSS rule and
// check for invalid classes
root.walkRules((rule) => {
const classNames = rule.selector.split('.').slice(1);
classNames.forEach((className) => {
if (className.startsWith('invalid-')) {
stylelint.utils.report({
ruleName,
result,
node: rule,
message: messages.invalidClass(className),
});
}
});
});
};
});
plugin.ruleName = ruleName;
plugin.messages = messages;
module.exports = plugin;
Step 4: Create a Stylelint configuration file called ".stylelintrc.js" and add the following code to configure Stylelint to use your custom plugin.
JavaScript
module.exports = {
plugins: ['./custom-plugin.js'],
rules: {
'custom-plugin/no-invalid-classes': true,
},
};
Step 5: Open cmd and run the following command to lint your CSS using stylelint.
npx stylelint yourcssfilelicaton
Example: This is the basic example that illustrates including the @tailwind CSS rule to CSS checker to check the error in the Tailwind code.
Step 1: Write your HTML and CSS code.
HTML
<html>
<head>
<meta charset="UTF-8">
<title>Custom plugin</title>
<link rel="stylesheet"
href="styles.css">
</head>
<body>
<h1 class="valid-class">
Valid Heading
</h1>
<p class="invalid-class">
Invalid Paragraph
</p>
</body>
</html>
CSS
.valid-class {
color: blue;
}
.invalid-class {
color: red;
}
Step 2: Run Stylelint
npx stylelint styles.css
Output:

Approach 2: Using manual configuration
Some CSS checkers allow configuring custom rules through a configuration file. You can define the @tailwind CSS rules within the configuration file specifying the valid class names, properties, and values that should pass the validation.
Steps to Install & Configure manually:
Step 1: Create a new npm project. Run the following command to initialize a new npm project.
npm init -y
Step 2: Install ESlint and the ESlint plugin for Tailwind CSS.
npm install eslint eslint-plugin-tailwindcss --save-dev
Step 3: Make an ESlint configuration file called ".eslintrc.js" in your project directory and add your tailwind-specific rules inside it.
JavaScript
module.exports = {
plugins: ['tailwindcss'],
rules: {
'tailwindcss/no-invalid-classes': 'error',
},
};
Step 4: Finally Run the ESlint using this command
npx eslint --ext .css yourcssfilelocation
Example: This is another example that illustrates adding the @tailwind CSS rule to CSS checker by configuring manually.
Step 1: Write your HTML and CSS code
HTML
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet"
href="styles.css">
</head>
<body>
<h1 class="text-center font-bold">Hello</h1>
<div class="bg-blue-500">
<p class="invalid-class">This class is not valid.</p>
</div>
</body>
</html>
CSS
/* styles.css */
.invalid-class {
color: red;
}
Step 2: Run ESlint
npx eslint --ext .css styles.css
Output:

Similar Reads
How to Style Checkboxes in Tailwind CSS ?
In Tailwind CSS, you can style checkboxes using utility classes to customize their appearance. You can use utility classes like appearance-none to remove the default browser styles from checkboxes. ApproachBegin with the basic HTML structure, including the <!DOCTYPE html> declaration, <html
3 min read
How to Add New Colors in Tailwind CSS ?
Tailwind CSS is a popular utility-first CSS framework that offers a wide range of pre-designed styles and classes to simplify the process of styling web applications. However, the default set of colors provided by Tailwind may not always meet the requirements of your project. In such cases, you may
4 min read
How to add @keyframes to a Tailwind CSS config file ?
Tailwind CSS is a utility framework in which we cannot add @keyframes through any built-in method directly to the configuration file. @Keyframes are used to invoke animation effects to our element. There are various ways to add @keyframes in a Tailwind CSS config file. Table of Content Using Externa
3 min read
How to Access Tailwind Colors from JavaScript ?
Tailwind CSS is a "Utility first CSS framework". The feature that makes Tailwind has a variety of classes and provides a huge set of predefined colors that can be used in our stylesheets without the need to define them manually. These predefined colors are categorized into different color palettes w
4 min read
How to Add Tailwind CSS to HTML ?
Tailwind CSS is a utility-first framework offering pre-defined classes for rapid styling of HTML elements. It simplifies customization and accelerates web development workflows.Integration Options:CDN Integration: Quickly add Tailwind CSS via a CDN link in the <head> of your HTML.Using npm: In
3 min read
How To Add Custom Box Shadow In Tailwind CSS?
Tailwind CSS is a utility-focused CSS framework. Offers a wide range of design utilities. It does include predefined shading, however, for unique design needs, you might want a custom box shadow that goes beyond the default. in this article, you will learn how to extend Tailwind's default shadow and
3 min read
How to Create Tailwind CSS Profile Card in React?
TailwindCSS can be integrated with React to create highly customizable and responsive profile cards by using utility-first classes for styling. This approach allows you to design visually appealing cards with gradients, rounded corners, and interactive animations, all while ensuring seamless respons
3 min read
How to create a Chevron using Tailwind CSS ?
A Chevron is a basic geometric shape that is used in websites to indicate directional movements or navigation. By utilizing specific border properties and transformations, a chevron shape can be achieved without the need for custom CSS. Tailwind's utility-first approach allows for a straightforward
3 min read
How to Add Rounded Corners to an Image in Tailwind CSS ?
Adding rounded corners to an image in Tailwind CSS is an easy way to make your pictures look nicer. Instead of having sharp corners, you can give them smooth, rounded edges. Tailwind CSS has simple classes that let you choose how rounded the corners are, whether just a bit or completely round. Appro
3 min read
How to add a style on a condition in Tailwind CSS ?
In this article, we will see how to integrate conditional styling into our web projects using Tailwind CSS. There are various Tailwind CSS classes are available, although, it usually involves dynamically adding or removing classes using JavaScript. There are different approaches to implementing the
3 min read