- Published on
Fixing Unknown at rule @tailwind css(unknownAtRules)
- Authors
- Name
- Ripal & Zalak
How to Fix Unknown @tailwind CSS Rule Errors
When using Tailwind CSS, developers often encounter the error "Unknown at rule @tailwind" in their CSS checkers, especially in Visual Studio Code. This issue can cause warnings or block proper rendering of styles. In this guide, we’ll explore solutions to fix this problem effectively.
What Causes the Error?
The error occurs because CSS checkers don’t natively recognize Tailwind-specific directives like @tailwind base;
, @tailwind components;
, and @tailwind utilities;
. These are unique to Tailwind and need specific configurations to be handled correctly.
Solutions to Fix the @tailwind Rule Error
1. Install Tailwind CSS IntelliSense
The easiest and most recommended way to fix this issue is by installing the Tailwind CSS IntelliSense extension in Visual Studio Code. This plugin provides:
- Autocompletion for Tailwind classes.
- Syntax highlighting for Tailwind-specific rules.
- Elimination of validation warnings for
@tailwind
directives.
Steps to Install:
- Open Visual Studio Code.
- Navigate to the Extensions Marketplace (
Ctrl + Shift + X
). - Search for Tailwind CSS IntelliSense and click Install.
2. Update Your VS Code Settings
Add specific configurations in the settings.json
file to associate your CSS files with Tailwind CSS.
Steps:
- Open the command palette (
Ctrl + Shift + P
) and search forPreferences: Open Settings (JSON)
. - Add the following code:
{
"files.associations": {
"*.css": "tailwindcss"
},
"editor.quickSuggestions": {
"strings": true
}
}
This ensures .css
files are treated as Tailwind CSS files, enabling proper support and eliminating warnings.
3. Configure CSS Linter to Ignore Tailwind Rules
If you’re using a linter like Stylelint, configure it to ignore unknown at-rules.
Steps:
- Create a
.stylelintrc
file in your project root. - Add the following configuration:
{
"extends": "stylelint-config-recommended",
"rules": {
"at-rule-no-unknown": [
true,
{
"ignoreAtRules": ["tailwind", "apply", "layer", "variants", "responsive", "screen"]
}
]
}
}
This ensures that Tailwind-specific rules are ignored by the linter.
4. Use PostCSS Language Support
Install the PostCSS Language Support extension for Visual Studio Code and associate your CSS files with PostCSS.
Steps:
- Install the PostCSS Language Support extension.
- Update your
settings.json
file:
{
"files.associations": {
"*.css": "postcss"
}
}
This approach is particularly useful if you’re using PostCSS in your build pipeline.
5. Ignore Warnings (Temporary Solution)
If you need a quick fix and don’t want to address the root cause, you can disable the warnings by adding the following setting:
{
"css.lint.unknownAtRules": "ignore"
}
This method suppresses the warning but may not be ideal for long-term use.
FAQ
Q1: Does this issue affect SCSS files?
Yes, SCSS files may also display similar warnings. You can disable SCSS validation by adding:
{
"scss.validate": false
}
Alternatively, use PostCSS or configure your linter accordingly.
Q2: What if I don’t want to change global settings?
You can add a workspace-specific .vscode/settings.json
file in your project directory:
{
"files.associations": {
"*.css": "tailwindcss"
}
}
This ensures the changes only apply to the current project.
@tailwind
directive in Vue or React projects?
Q3: Can I use the Yes, but ensure your build tool (e.g., Webpack, Vite) is configured to process Tailwind CSS directives. Refer to the Tailwind CSS documentation for setup details.
Tips and Tricks
For more tips and tricks, check out the Tailwind CSS official documentation.