10

TailwindCSS IntelliSense in VSCode is not working when I use it with the TailwindCSS "Play CDN". I don't use any more configuration.

I installed TailwindCSS IntelliSense and then created a sample project following the Play CDN guide, but neither autocompletion, hinting, nor any other features that TailwindCSS IntelliSense should provide are working.

4

5 Answers 5

37

This is a kind of work around:

Just create a file tailwind.config.js in root directory of project. And it will work as charm.

Even if there is no content inside the file, the Tailwind intellisense will work while using Play CDN of tailwind.

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

4 Comments

Just creating a file won't work. The contents of the file should be at least: module.exports = { content: ['./src/**/*.{html,js}'], theme: {}, };
@Brampage actually seems to work with an empty file (VSCode v1.81.1, Tailwind CSS IntelliSense v0.9.13, Microsoft Windows 11 Pro)
@Brampage Solution actually worked for me. I did not edit settings.json. Just create tailwind.config.js in root directory of project and add "module.exports = { content: ['./src/**/*.{html,js}'], theme: {}, };" in it. Thanks!
Works for me with an empty tailwind.config.js file
2

I’m using Tailwind via CDN and IntelliSense wasn't working either. I fixed it by creating a minimal:

tailwind.config.js:

module.exports = {
  content: ["./**/*.html"],
};

And adding this to .vscode/settings.json:

{
  "editor.quickSuggestions": { "strings": true },
  "tailwindCSS.includeLanguages": { "html": "html" },
  "tailwindCSS.experimental.configFile": "./tailwind.config.js"
}

2 Comments

Using the CDN increases client load and page load time. Tailwind should not be used via CDN at all. It is a compiler tool that generates the required CSS based on the class names you use in your source. It only needs to be compiled once before production during the build step - there's no need to repeat this for every client on each page load.
0

Here's how I fixed it for Tailwind CDN usage...

All you need to do, is to just add this @import "tailwindcss"; to your css file.

This would help bridge gap for Intellisense and the editor will recognize tailwind classes. Then add the CDN Link in your html:

<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>

Now your IntelliSense should show Tailwind classes properly in the editor, and Tailwind will also work in the browser.

4 Comments

This is an unsafe and irresponsible piece of advice. Using the CDN increases client load and page load time. Tailwind should not be used via CDN at all. It is a compiler tool that generates the required CSS based on the class names you use in your source. It only needs to be compiled once before production during the build step - there's no need to repeat this for every client on each page load.
While you’re correct about using libraries in production, the above user’s answer still serves a purpose. Sometimes people just want to experiment or play around with a library before going through the hassle of installing and configuring it, to know if it's worth the shot or not. For that purpose, using a CDN is perfectly valid—it solves the immediate need without causing any harm. I don't think this is a valid criticism given the fact that the user merely answered the question and didn't provided any "advice" at all.
You still need to use the official VSCode extension PLUS apply the configuration from the docs and my suggested settings in settings.json: follow steps (important) and customize (just extra reference).
0

Stop using the CDN!

Do not use the CDN for project development, and especially avoid including it in production.

Why?

The CDN generates the CSS on every single page load. This is a disadvantage for production projects because it adds extra load for every client on every page load and slows down page rendering.

Another reason is that generating TailwindCSS's CSS is not needed every time - it only needs to happen when the class names in your source files change, so it only needs to be generated once per build.

Every Tailwind plugin works this way, and a watch mode is provided for development so you don't have to manually recompile endlessly while working.

Alternatives

If you don't want to use Node and npm, then clearly it's better to choose the Standalone version. It's just an executable file that you download and run. If you choose one of these installations instead of the CDN from the start, the question wouldn't even arise, because they require at least a minimal configuration.

If you have no issues with Node and npm, in addition to the CLI, two plugins are also available - you can use either one depending on your project.

So why doesn't TailwindCSS IntelliSense work with the Play CDN?

The reason is that TailwindCSS IntelliSense detects the package.json in your project and checks the installed TailwindCSS version. Without that, it looks for a configuration file.

When using a CDN, it clearly cannot find a version number, because nothing is installed. It also won't find a configuration, because the CDN works without it - it's only published for playgrounds (for example, embedding in a StackOverflow snippet). For TailwindCSS IntelliSense to start working, you need at least a configuration. This differs between v3 and v4.

TailwindCSS v3 CDN + IntelliSense

You need a tailwind.config.js with the following content:

/** @type {import('tailwindcss').Config} */
export default {
  content: ["./src/**/*.{html,js}"],
  theme: {
    extend: {},
  },
  plugins: [],
}

Then, you must pass the path to this file in your VSCode configuration like this:

{
  "tailwindCSS.experimental.configFile": "./tailwind.config.js"
}

Of course, provide the correct path and customize it relative to your setup. Place the configuration project-specifically in {your-project}/.vscode/settings.json, so the path only applies to the current project. (You can place it globally as well, but that will affect all future projects.)

See more: Workspace settings.json location

TailwindCSS v4 CDN + IntelliSense

You need a main CSS file, e.g., main.css, with the following content:

@import "tailwindcss";

Then, you must pass the path to this file in your VSCode configuration like this:

{
  "tailwindCSS.experimental.configFile": "./css/main.css"
}

Of course, provide the correct path and customize it relative to your setup. Place the configuration project-specifically in {your-project}/.vscode/settings.json, so the path only applies to the current project. (You can place it globally as well, but that will affect all future projects.)

See more: Workspace settings.json location

Other

1 Comment

-1

Try to invalidate cache / remove node modules and yarn/npm your project again.

1 Comment

What does this have to do with the CDN? There's no mention of npm or caching in the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.