310

Tailwind CSS adds a @tailwind CSS at rule which is flagged as unknown.

How can I avoid this error?

For example, styles.css

@tailwind preflight;

@tailwind utilities;

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Steve Lee
  • 5,191
  • 5
  • 17
  • 18

23 Answers23

372

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" }.

Kong
  • 8,792
  • 15
  • 68
  • 98
Fasani
  • 5,141
  • 1
  • 23
  • 24
  • 11
    Doesn't seem to work with VueJS, Volar, and .vue files – ken Aug 09 '21 at 22:04
  • 64
    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" }` – Qortex Sep 08 '21 at 16:11
  • 13
    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... – Magnus Bull Dec 03 '21 at 08:00
  • 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. – René Schubert Jan 06 '22 at 11:15
  • https://github.com/tailwindlabs/tailwindcss/discussions/5258#discussioncomment-1979394 This will be quicker solution. – Aakash Jun 28 '22 at 15:50
  • it`s actually work with react project – lazuardi_fenjano Feb 22 '23 at 14:56
255

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.

davecardwell
  • 3,380
  • 1
  • 17
  • 15
  • 4
    > 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. – KubaJastrz Jun 21 '20 at 12:54
  • 2
    This is a partial solution, unlike installing PostCSS Language Support suggested in https://stackoverflow.com/a/62801203/640208. – arpad Apr 04 '21 at 13:10
  • 2
    I truly prefer this solution rather than installing unnecessary packages. – Guilherme Crozariol Aug 23 '21 at 20:33
  • 1
    I added a section for `@apply` and it worked for me. I did have to reload VS Code first. – Magnus Bull Dec 03 '21 at 07:57
  • 2
    @MagnusBull it seems to work for providing intellisense when you use it, but did you also get rid of your squiggles for the `unknownAtRules`? I get the documentation pop up as I use `@apply` but still continue to have the underlining error message. – Joseph Bradshaw Jan 23 '22 at 18:00
  • 1
    @JosephBradshaw Yes, I was able to get rid of the yellow warning squiggles. I seem to remember it happening at the same time as I applied this config and reloaded VS Code: https://imgur.com/a/zhgEPko – Magnus Bull Jan 26 '22 at 07:26
  • 1
    Perfect answer: removes squiggly lines, retains IntelliSense and even adds additonall IntelliSense. Plus, I didn't need to reload VS Code. – khaki May 16 '22 at 12:25
  • 4
    Additionally to install the extension, you also need to set the "files.associations" setting as described under the "Recommended VS Code Settings" section here: https://marketplace.visualstudio.com/items?itemName=bradlc.vscode-tailwindcss – kunnix Jul 07 '22 at 23:43
  • 10
    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_. – datalifenyc Aug 06 '22 at 14:57
  • 2
    Could you edit this response to include this info^ – Chris Z Oct 31 '22 at 15:38
  • 1
    The files.associations did not work for me, but I just changed the file type from CSS to tailwindcss with the button "CSS" in the status bar on the lower right. – kirbby Nov 04 '22 at 21:37
  • 1
    I JUST installed (Nov 2022) the Tailwind plugin first, and still got the warning. The PostCSS plugin was still required for me /shrug, but I now see the filetype I should have switched to and that works too. – mix3d Nov 12 '22 at 03:21
  • 1
    @ChrisZ I added a link to the recommended settings part of the extension documentation. – davecardwell Nov 17 '22 at 18:44
  • The "old" answer is still the better one. The Tailwind CSS Intellisense plugin when used with `"files.associations": { "*.css": "tailwindcss" }` breaks other linting rules in css files. – adroste Nov 29 '22 at 22:50
127

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. More information about Stylelint's configuration follow this link: https://stylelint.io/user-guide/

{
  "extends": "stylelint-config-recommended",
  "rules": {
    "at-rule-no-unknown": [ true, {
      "ignoreAtRules": [
        "extends",
        "tailwind"
      ]
    }],
    "block-no-empty": null,
    "unit-allowed-list": ["em", "rem", "s"]
  }
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
hasusuf
  • 1,548
  • 1
  • 9
  • 14
  • 2
    The install is quite straight forward. It is exactly those 4 steps as shown. – agm1984 Nov 21 '18 at 20:47
  • 4
    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). – Abdalla Arbab Jan 23 '19 at 11:31
  • @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 Mar 12 '20 at 08:27
  • @RamboNo5 The configuration is relevant to the [stylelint-config-recommended](https://github.com/stylelint/stylelint-config-recommended#extending-the-config) – hasusuf Mar 15 '20 at 19:01
  • shinnn.stylelint extension has been deleted so this is irrelevant now. – Ahmad Awais Jul 30 '20 at 02:32
  • Step 3 works for me. No need for step 4. Thank you! – Mark Oct 29 '20 at 06:26
  • Not working for me, and only shows more errors on my very simple css rule ```.button { @apply p-1; }``` – devaent Jul 18 '21 at 00:29
  • 'unit-whitelist' has been deprecated. Instead use 'unit-allowed-list'. See: https://github.com/stylelint/stylelint/blob/13.7.0/lib/rules/unit-whitelist/README.md – seokgyu Aug 07 '21 at 03:22
  • If you are using Vuejs and Vetur, make sure to use “vetur. – VikingBarrister Dec 21 '21 at 13:45
  • If using Vue and Vetur, and you want to switch off the css validation within the – VikingBarrister Dec 21 '21 at 14:07
  • I found that I had to `npm install --save-dev stylelint` as well, or the Stylelint extension won't do anything unless you have it installed globally. (You can test if it's working by typing `color: #12;`.) The `"block-no-empty"` and `"unit-allow-list"` rules don't need to be changed (they're unrelated), and Tailwind doesn't add an `@extends` rule, so you should be able to do this: `"at-rule-no-unknown": [ true, { "ignoreAtRules": ["tailwind"] } ]` – Jo Liss Nov 25 '22 at 13:35
  • The link is broken: *"Page Not Found. We could not find what you were looking for. Please contact the owner of the site that linked you to the original URL and let them know their link is broken."* – Peter Mortensen Mar 29 '23 at 22:16
45

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
fahad saleem
  • 616
  • 6
  • 8
  • 50
    The question is how to ADD tailwind support. Ignoring it and skipping the syntax awareness is a terrible answer. – doublejosh May 14 '21 at 16:36
  • 4
    this is a great and simple answer! it does not require installing dangerous plugins to solve a simple issue. thanks! – checklist Sep 17 '21 at 07:13
  • 1
    @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. – Davo Feb 08 '23 at 08:32
  • 1
    It's a great answer as it specifically states that it ignores the warning. It's up to developer to take the risk. RTFM – checklist Feb 09 '23 at 04:40
  • 2
    switching to using tailwindcss for file associations is a much better approach since it actually fixes this specific issue rather than ignoring all warnings. – Nick Lothian May 25 '23 at 05:21
  • @NickLothian "Tailwind CSS IntelliSense" will work anyway. Ignoring the "Unknown At Rules" just silencing the ESLint. – Tires Jul 25 '23 at 09:15
39

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
      }
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jorge Garcia
  • 2,042
  • 23
  • 25
29

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ace.C
  • 1,201
  • 12
  • 22
  • 5
    The PostCSS language support extension now binds to .css files too, so no need to change the extension – Zack Jan 18 '21 at 22:51
  • I did something similar to this calling the files `filename.pcss.css` to keep some trace of what is css vs postcss. – Fasani May 07 '21 at 13:57
18

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
jaycedotbin
  • 321
  • 3
  • 4
16

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://www.codeconcisely.com/posts/tailwind-css-unknown-at-rules/

In this way you dont need to install any third plugins or ignore any error. Thanks for reading!

Biolo Account
  • 196
  • 2
  • 6
13

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,
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
agm1984
  • 15,500
  • 6
  • 89
  • 113
13

Just add three lines into the settings.json file:

"css.lint.unknownAtRules": "ignore",
"css.validate": true,
"scss.validate": true,
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jignesh Joisar
  • 13,720
  • 5
  • 57
  • 57
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

Nik
  • 143
  • 2
  • 9
6

After many tests:

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

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

Settings> User setting:

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

CSS Intellisence is incomplete

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
nencode
  • 69
  • 1
  • 3
5

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"
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Blues Clues
  • 1,694
  • 3
  • 31
  • 72
2

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
0xe1λ7r
  • 1,957
  • 22
  • 31
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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 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. – bot19 Jul 12 '23 at 02:59
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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
1

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

Search for Unknown At Rules.

Change Lint from warning to ignore.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
AYGTX
  • 173
  • 2
  • 3
1

Is your tailwind rules inside a scss (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. You need to include it in a sccs file or other? 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 angular bracket <> with your filename and filepath.

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 1
    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. – linkdd Feb 16 '22 at 01:50
0

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 2
    This plagiarises at least one previous answer, [fahad saleem's answer](https://stackoverflow.com/questions/47607602/how-to-add-a-tailwind-css-rule-to-css-checker/64211089#64211089). – Peter Mortensen Mar 29 '23 at 23:08
0

Adding for future reference

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

This should resolve the issue.

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
0

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

Emma
  • 658
  • 10
  • 20
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/34861760) – Ram Chander Aug 24 '23 at 12:46
-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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Hiroshi Nishio
  • 222
  • 4
  • 11