385

Tailwind CSS adds a @tailwind CSS at rule which is flagged as unknown. How can I avoid this error?

@tailwind preflight;
@tailwind utilities;

Warning: Unknown at rule @tailwind css(unknownAtRule)

5

30 Answers 30

432

If you use Visual Studio Code, you can use the PostCSS Language Support plugin.

Make sure you associate your scss files with PostCSS by adding the following to your settings.json file: "files.associations": { "*.scss": "postcss" }.

Sign up to request clarification or add additional context in comments.

6 Comments

Doesn't seem to work with VueJS, Volar, and .vue files
For those like me who want to use this on .scss files (Angular app in my case), add this to your settings.json: "files.associations": { "*.scss": "postcss" }
While this got rid of the warning for me, it also disabled all intellisense for CSS. I can only assume I did something wrong or forgot a step, but hard to say what step could be forgotten when there is only 1...
@MagnusBull You did nothing wrong. The mentioned extension does not work well with IntelliSense. You could try using this one: mhmadhamster.postcss-language which has a little better IntelliSense support, but I think it does not integrate with the @tailwind directive. At least I didn't get it to work.
|
303

2022-05 Update

The official Tailwind CSS IntelliSense extension now extends the built-in CSS language mode to fix these lint warnings, without losing any of VS Code’s default IntelliSense features.

Review the Recommended VS Code Settings section to enable this for all CSS files in your workspace.

I leave my original answer intact below if you don’t want to install an additional extension, but since v0.8.0 it no longer conflicts with the built-in CSS support so that would be my recommended approach.


Old Answer Without Extension

Visual Studio Code allows you to define Custom Data for CSS Language Service.

For example, in your workspace’s .vscode/settings.json you can add:

{
  "css.customData": [".vscode/css_custom_data.json"]
}

And then in .vscode/css_custom_data.json add:

{
  "atDirectives": [
    {
      "name": "@tailwind",
      "description": "Use the @tailwind directive to insert Tailwind’s `base`, `components`, `utilities`, and `screens` styles into your CSS.",
      "references": [
        {
          "name": "Tailwind’s “Functions & Directives” documentation",
          "url": "https://tailwindcss.com/docs/functions-and-directives/#tailwind"
        }
      ]
    }
  ]
}

Note that you may have to reload the VS Code window for the change to be picked up.

Here is a copy of .vscode/css_custom_data.json, which contains all directives with short usage snippets (which in turn get syntax highlighted in vs code):

{
  "version": 1.1,
  "atDirectives": [
    {
      "name": "@tailwind",
      "description": "Use the `@tailwind` directive to insert Tailwind's `base`, `components`, `utilities` and `screens` styles into your CSS.",
      "references": [
        {
          "name": "Tailwind Documentation",
          "url": "https://tailwindcss.com/docs/functions-and-directives#tailwind"
        }
      ]
    },
    {
      "name": "@responsive",
      "description": "You can generate responsive variants of your own classes by wrapping their definitions in the `@responsive` directive:\n```css\n@responsive {\n  .alert {\n    background-color: #E53E3E;\n  }\n}\n```\n",
      "references": [
        {
          "name": "Tailwind Documentation",
          "url": "https://tailwindcss.com/docs/functions-and-directives#responsive"
        }
      ]
    },
    {
      "name": "@screen",
      "description": "The `@screen` directive allows you to create media queries that reference your breakpoints by **name** instead of duplicating their values in your own CSS:\n```css\n@screen sm {\n  /* ... */\n}\n```\n…gets transformed into this:\n```css\n@media (min-width: 640px) {\n  /* ... */\n}\n```\n",
      "references": [
        {
          "name": "Tailwind Documentation",
          "url": "https://tailwindcss.com/docs/functions-and-directives#screen"
        }
      ]
    },
    {
      "name": "@variants",
      "description": "Generate `hover`, `focus`, `active` and other **variants** of your own utilities by wrapping their definitions in the `@variants` directive:\n```css\n@variants hover, focus {\n   .btn-brand {\n    background-color: #3182CE;\n  }\n}\n```\n",
      "references": [
        {
          "name": "Tailwind Documentation",
          "url": "https://tailwindcss.com/docs/functions-and-directives#variants"
        }
      ]
    }
  ]
}

Here's a preview of the result:

preview of @screen directive

The only directive missing is @apply, because it's declared at the CSS property level. The CSS Language Service probably doesn't expect atRules at the property level and won't pick up such directives.

16 Comments

> Note that you will have to reload the VS Code window for the change to be picked up. ~~~ It loaded instantly for me (VSCode 1.46.1 Win10). Thanks for all directives list.
This is a partial solution, unlike installing PostCSS Language Support suggested in stackoverflow.com/a/62801203/640208.
I truly prefer this solution rather than installing unnecessary packages.
Additionally to install the extension, you also need to set the "files.associations" setting as described under the "Recommended VS Code Settings" section here: marketplace.visualstudio.com/…
In the settings.json file, add "files.associations": { "*.css": "tailwindcss" } or you can use the File: Associations settings GUI: 1. Click Add Item; 2. Enter *.css for Item and tailwindcss for Value.
|
131

This is the at-rule-no-unknown rule provided by Visual Studio Code's built-in list.

In order to get rid of it you need to do the following:

1. Install the Stylelint extension code --install-extension stylelint.vscode-stylelint

2. Install the Stylelint recommended configuration npm install stylelint-config-recommended --save-dev

3. Add these two lines in your Visual Studio Code USER SETTINGS

"css.validate": false, // Disable default CSS built-in lint
"stylelint.enable": true, // Enable Stylelint
"scss.validate": false, // Disable SCSS lint (optional if using scss)

4. Paste these lines into a file called .stylelintrc in your project's root directory; create it if it does not exist.

{
  "extends": "stylelint-config-recommended",
  "rules": {
    "at-rule-no-unknown": [ true, {
      "ignoreAtRules": [
        "extends",
        "tailwind"
      ]
    }],
    "block-no-empty": null,
    "unit-allowed-list": ["em", "rem", "s"]
  }
}

12 Comments

The install is quite straight forward. It is exactly those 4 steps as shown.
I was able to hide the warning by only installing stylelint extension & disabling build-in css, scss, and less lint & enabling stylelint extension (No further steps).
@hasusuf Thanks, it works! But what is about block-no-empty and unit-whitelist? This is not needed here, right? Tailwind itself has px units, so I don't understand why they are not whitelisted here. Is this just personal preference?
@RamboNo5 The configuration is relevant to the stylelint-config-recommended
shinnn.stylelint extension has been deleted so this is irrelevant now.
|
58

Currently Recommended Visual Studio Code Settings (Updated 2022-12-15)

Official Tailwind CSS IntelliSense Visual Studio Code Documentation

Use the files.associations setting to tell Visual Studio Code to always open .css files in Tailwind CSS mode:

    "files.associations": {
      "*.css": "tailwindcss"
    }

Tip: Press Ctrl + , from Visual Studio Code to open Settings; then, type "Files Associations".

By default Visual Studio Code will not trigger completions when editing "string" content, for example within JSX attribute values. Updating the editor.quickSuggestions setting may improve your experience:

    "editor.quickSuggestions": {
      "strings": true
    }

Combining both, your settings.json file (if new) will look similar to this:

    {
        "files.associations": {
          "*.css": "tailwindcss"
        },
        "editor.quickSuggestions": {
            "strings": true
        }
    }

Source: Tailwind CSS IntelliSense


Previously Recommended Visual Studio Code Settings (Deprecated)

Visual Studio Code has built-in CSS validation which may display errors when using Tailwind CSS-specific syntax, such as @apply. You can disable this with the css.validate setting:

"css.validate": false

The "editor.quickSuggestions" setting recommendation remains the same then and now. Combining both, your settings.json file (if new) would look similar to this:

{
    "css.validate": false,
    "editor.quickSuggestions": {
        "strings": true
      }
}

1 Comment

This is the answer, not ignoring CSS> Lint:Unknown At Rules within VS Code, cheers Jorge!
57

I am new here but the simplest answer to solve this is to follow these steps:

  1. Open the CSS file where you import Tailwind CSS

  2. Press Ctrl + Shift + P and search for “change language mode”

  3. Inside the search bar, type “tailwindcss” and select it.

  4. Now your CSS file is associated with Tailwind CSS instead of regular css and the warnings should be gone.

Credit to : https://batchnepal.com/topic/fix-unknown-at-rule-warning-in-vscode

In this way you won't need to install any third plugins or ignore any error. Make sure to install Official VSCode extension for tailwindcss . Thanks for reading!

3 Comments

I found the same page and it was the best approach and you don't need to do anything else editing files.
This does not work for files that have mixed languages, like any regular component of a modern framework.
I had to install the tailwind.css VSCode extension, as when I tried this without that, the option of Tailwind wasn't in the drop down. Now it is, and it works.
50

1. Just go to settings (Ctrl + , for a shortcut).

2. Search for CSS in the search bar.

3. look for the "CSS > Lint: Unknown At Rules"

4. Select "ignore" from the dropdown options.

This ignores the warning. If you're OK with it.

7 Comments

The question is how to ADD tailwind support. Ignoring it and skipping the syntax awareness is a terrible answer.
this is a great and simple answer! it does not require installing dangerous plugins to solve a simple issue. thanks!
@checklist this is a horrible answer. It ignores the problem instead of solving it. There is a reason why this rule exists, it is to prevent from typing unknown at rules... by disabling it you are removing that safeguard.
It's a great answer as it specifically states that it ignores the warning. It's up to developer to take the risk. RTFM
switching to using tailwindcss for file associations is a much better approach since it actually fixes this specific issue rather than ignoring all warnings.
|
30

My recommendation is to install PostCSS language support and then rename tailwind.css to tailwind.pcss. Then change the references in your package.json scripts (or whatever build scripts you are using for tailwind) to tailwind.pcss from tailwind.css and everything should work fine.

The @apply rule is compatible with postCSS: Does @apply in Tailwind conflict with @apply in postcss-cssnext? #325

3 Comments

The PostCSS language support extension now binds to .css files too, so no need to change the extension
I did something similar to this calling the files filename.pcss.css to keep some trace of what is css vs postcss.
There's no need to use a PostCSS extension. Instead, use the official TailwindCSS IntelliSense extension, which is compatible with both v3 and v4 versions.
22

According to the tailwindcss-intellisense GitHub repository:

Recommended Visual Studio Code Settings

files.associations

Use the files.associations setting to tell Visual Studio Code to always open .css files in Tailwind CSS mode:

"files.associations": {
   "*.css": "tailwindcss"
}

It fixed the @tailwind warning and added Tailwind CSS directives, functions to intellisense.

More information about the Tailwind CSS intellisense extension can be found in the GitHub repository.

Comments

16

SCSS

If you are using Sass with Tailwind CSS, you will still see errors in your .scss files using these earlier answers to this question.

To properly lint Sass, you can add to your Visual Studio Code settings:

"scss.validate": false,

Follow the instructions by hasusuf, but turn off the default Visual Studio Code validator:

Add these three settings:

"css.validate": false,
"scss.validate": false,
"stylelint.enable": true,

1 Comment

Disabling the warnings is not the best solution. The official TailwindCSS IntelliSense extension would be a real solution instead.
14

Just add three lines into the settings.json file:

{
  // ....
  "css.lint.unknownAtRules": "ignore",
  "css.validate": true,
  "scss.validate": true,
}

4 Comments

This worked for me. Plain and simple. Thanks. (VS version 1.52.1)
This doesn't "work" ...it just turns all the intelligence off. Ugh!
it worked for me adding only this "scss.lint.unknownAtRules": "ignore", notice the s before scss. since thats what i am using! thanks!
Disabling the warnings is not the best solution. The official TailwindCSS IntelliSense extension would be a real solution instead.
11

Without touching VS code's global settings, you can fix it with a local setting file for your specific project which you use tailwindcss in. Also you can safely commit this file to your repo so that your team mate's VS code also picks it.

Create a folder named .vscode in your project root (If not existing already) and add a file named settings.json in that.

Paste the following directive in that file (Or if the file already exists, append it to that)

// <project-root>/.vscode/settings.json

{
  "files.associations": {
    "*.css": "tailwindcss"
 }
}

Comments

8

I edited my .vscode/settings.json file by adding in "css.validate": false, seemed to work for me without installing external libraries.

https://github.com/Microsoft/vscode/issues/14999#issuecomment-258635188

1 Comment

Disabling the warnings is not the best solution. The official TailwindCSS IntelliSense extension would be a real solution instead.
7

This works for me when dealing with CSS and SCSS. In your settings.json file, add/edit the code below.

"files.associations": {
    "*.css": "tailwindcss",
    "*.scss": "tailwindcss"
}

1 Comment

For workspace-wide settings, use the ./.vscode/settings.json file, relative to the project folder.
6

After many tests:

The PostCSS and STYLUS syntax highlighter remove warnings, but CSS Intellisence is incomplete. It does not show the first-utilities classes Tailwind.

I installed 'language-stylus' plugin, in Visual Studio Code.

Settings> User setting:

"files.associations": {
   "* .css": "stylus"
 },

CSS Intellisence is incomplete

1 Comment

There's no need to use a PostCSS extension. Instead, use the official TailwindCSS IntelliSense extension, which is compatible with both v3 and v4 versions.
4

Are your Tailwind rules inside a .scss file (or others stylesheet) files?

Please follow the Tailwind documentation and put the rules inside a .css (not scss or others).

  1. Rules are correctly detected?

    • No, go back to Tailwind documentation
    • Yes
  2. Do you need to include it in a sccs file or other? Then do the following:

    • In style.scss, remove all Tailwind CSS rules and add the line:

      @import "<path_to_my_tailwind_conf>";
      
    • <my_tailwind_conf>.css:

      @tailwind base;
      @tailwind components;
      @tailwind utilities;
      

Replace the string inside the angle bracket, <>, with your filename and filepath.

2 Comments

Questions do not belong in answers, even if rhetorical. Stack Overflow is not a forum.
4

Update 2024 I solved this waring In VSCode Unknown at rule @tailwind by install this extensions " PostCSS Language Support " from the marketplace

1 Comment

There's no need to use a PostCSS extension. Instead, use the official TailwindCSS IntelliSense extension, which is compatible with both v3 and v4 versions.
3

Add this Visual Studio Code extension to add the language support.

Comments

3

Adding for future reference

@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';

This should resolve the issue.

2 Comments

This seems highly unlikely to make a difference. Any more explanation here?
This is more of a workaround than a real solution. The official TailwindCSS IntelliSense extension provides support for all directives. With this answer, you’d only be suppressing the @tailwind warning.
2

Make sure to install PostCSS language support, an extension found in Visual Studio Code. That will remove the error that is displaying.

The @apply rule is compatible with PostCSS: Does @apply in Tailwind conflict with @apply in postcss-cssnext? #325

VS Marketplace: PostCSS Language Support

Note: uninstall PostCSS intellisense and highlighting extension from Visual Studio Code. Otherwise it will not work.

2 Comments

adding PostCSS Language Support instantly fixed it for me. I don't have the other 2 plugins. I didn't even need to reload VS Code.
There's no need to use a PostCSS extension. Instead, use the official TailwindCSS IntelliSense extension, which is compatible with both v3 and v4 versions.
2

Today Visual Studio Code is configurable. To get rid of this warning in your Visual Studio Code, you can create a folder named ".vscode" and create a new file called "settings.json". In the settings.json file you can paste this JSON content:

{
  "css.lint.unknownAtRules": "ignore"
}

Enter image description here

2 Comments

This gets rid of ALL warnings; not a very good solution.
Disabling the warnings is not the best solution. The official TailwindCSS IntelliSense extension would be a real solution instead.
2

1. You most do is to add to setting.json on VScode

"files.associations": {
  "*.css": "tailwindcss"
}

2. and this will solve your problem with index.css

@tailwind base;
@tailwind components;
@tailwind utilities; 

Source Information: https://marketplace.visualstudio.com/items?itemName=bradlc.vscode-tailwindcss

1 Comment

How is this different from the existing Answers?
1

Using Visual Studio Code, open user settings by Ctrl + ,.

Search for Unknown At Rules.

Change Lint from warning to ignore.

2 Comments

Besides lots of folk already suggesting this, ignoring an issue does not fix it.
Disabling the warnings is not the best solution. The official TailwindCSS IntelliSense extension would be a real solution instead.
1

I encountered the same problem, and after some troubleshooting, I found a solution that worked for me. If you're facing issues with the @tailwind CSS rule not being recognized by the CSS checker, follow these instructions:

  1. Go to settings ( Ctrl + , for a shortcut).

  2. Search for CSS in the search bar.

  3. Look for the "CSS > Lint: Unknown At Rules".

  4. Select "ignore" from the dropdown options.

Reference image

This should resolve the issue, and the CSS checker should recognize the @tailwind rule without any problems. Remember to save your changes and restart your development server or IDE for the changes to take effect.

2 Comments

We still need to real solution but at least for now we can hide warnings. Thanks.
Disabling the warnings is not the best solution. The official TailwindCSS IntelliSense extension would be a real solution instead.
1

Just Install this plugin and it works https://marketplace.visualstudio.com/items?itemName=csstools.postcss

2 Comments

Does that plugin work reliably? For me, it messed up the built-in CSS Intellisense features, such as the color picker.
There's no need to use a PostCSS extension. Instead, use the official TailwindCSS IntelliSense extension, which is compatible with both v3 and v4 versions.
0

You just need to add these into. Click menu FilePreferencessettings.json

"css.lint.unknownAtRules": "ignore",
"css.validate": true,
"scss.validate": true,

Add this code to settings.json.

2 Comments

Removing the error message is not a solution, now if I make a typo and write "@layre" it won't show up at the linting step.
Disabling the warnings is not the best solution. The official TailwindCSS IntelliSense extension would be a real solution instead.
0

we can remove this error by installing the extension PostCSS Language Support from the extensions search panel

2 Comments

This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
There's no need to use a PostCSS extension. Instead, use the official TailwindCSS IntelliSense extension, which is compatible with both v3 and v4 versions.
0

Try this if you using VS Code. Find PostCSS Language Support in the extensions marketplace and install it. That may help you.

1 Comment

There's no need to use a PostCSS extension. Instead, use the official TailwindCSS IntelliSense extension, which is compatible with both v3 and v4 versions.
0

TailwindCSS IntelliSense - VSCode Extension

These are custom TailwindCSS directives that CSS IDEs don't understand by default. For VSCode, use the official TailwindCSS IntelliSense extension.

As previously suggested, since v3, installing the TailwindCSS IntelliSense VSCode extension and applying additional configuration has been supported and recommended.

After that, tell VSCode that you want to treat your .css files as TailwindCSS. You can do this in the settings under files.associations like this:

{
  "files.associations": {
    "*.css": "tailwindcss",
    "*.scss": "tailwindcss",
  },
}

Since these are just IDE error messages, the code will work as expected if you have properly installed TailwindCSS. However, they can be frustrating, so it is definitely recommended to use the extension.

The TailwindCSS IntelliSense extension remains compatible with both v3 and v4 after the release of v4.

When using v4, an extra tailwind.config.js file is not required, but TailwindCSS must be imported for IntelliSense to automatically detect the installation.

If IntelliSense does not detect it, hints will not work, VSCode will not properly recognize TailwindCSS-specific directives, and it will generate many warnings.

To fix this issue, I have found the following solutions:

TailwindCSS v4

Support and improvements for TailwindCSS v4 are in progress. As of the fix in TailwindCSS Intellisense VSCode extension since February 2025 (v0.14.3), it is possible to specify the new CSS-first configuration as a configuration file.

Due to the proper v4 configuration detection, Intellisense will work the same way as in v3 without any additional settings. It remains compatible with both v3 and v4 versions simultaneously.

Tailwind CSS v4.x (CSS entrypoints)

For v4 projects, specify the CSS file(s) that serve as your Tailwind entrypoints.

If your project contains a single CSS entrypoint, set this option to a string:

"tailwindCSS.experimental.configFile": "src/styles/app.css"

For projects with multiple CSS entrypoints, use an object where each key is a file path and each value is a glob pattern (or array of patterns) representing the files it applies to:

"tailwindCSS.experimental.configFile": {
  "packages/a/src/app.css": "packages/a/src/**",
  "packages/b/src/app.css": "packages/b/src/**"
}

Additionally, it no longer displays an error message if the configuration file is missing in v4.

1 Comment

But it's worth going through the recommended troubleshooting steps, as certain special VSCode settings can cause these issues: stackoverflow.com/a/79808734/15167500
-1

If the Tailwind CSS is not working as well as the error caused by the unknown rule, you need to build it again. For example, if you have been running npm run dev in a local environment, you can exit with Ctrl + C and run npm run dev again to create a normal pure CSS file, which will enable tailwind CSS to work.

This is exactly the problem I was stuck with and how I was able to solve it.

Comments

-1

Just go to settings (Ctrl + ,) for shortcut.

Open the settings and search for “unknown”. The first result should be the one you’re looking for: CSS > Lint: Unknown At Rules:

Change that to ignore:

Done!

Still don’t understand? Follow the pictures:

Enter image description here

Enter image description here

enter image description here

2 Comments

This plagiarises at least one previous answer, fahad saleem's answer.
Disabling the warnings is not the best solution. The official TailwindCSS IntelliSense extension would be a real solution instead.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.