Setting up Tailwind CSS correctly the first time saves hours of debugging missing styles later. This lesson walks through installing Tailwind with npm, configuring content paths, and wiring it into a build tool.
What Does Tailwind Setup Involve?
A production-ready Tailwind setup has three pieces: the Tailwind package installed via npm, a configuration file that tells Tailwind which files to scan for class names, and a CSS file where Tailwind injects its generated styles.
Most modern frameworks (Vite, Next.js, Astro, Remix) provide official Tailwind integrations that automate most of this, but understanding the manual steps helps you debug configuration issues quickly.
The recommended installation method for any real project is npm, since it integrates with your existing build tool and enables the just-in-time compiler, custom configuration, and plugins.
The -p flag also generates a postcss.config.js file wired up with Autoprefixer.
Configuring Content Paths
The content array in tailwind.config.js tells Tailwind exactly which files to scan for class names. If a file isn't listed, any classes used only in that file will be missing from your final CSS.
Always include every file extension your project uses, including framework-specific ones like .astro or .vue.
Setup With Vite
Vite-based projects can use the official @tailwindcss/vite plugin (Tailwind v4) or the standard PostCSS pipeline (Tailwind v3) for the fastest development experience.
// vite.config.js
import { defineConfig } from "vite";
import tailwindcss from "@tailwindcss/vite";
export default defineConfig({
plugins: [tailwindcss()],
});
Common Mistakes
Forgetting to add every relevant file extension to the content array, which silently drops needed classes.
Linking the source CSS file directly instead of the compiled output file in production.
Not running the build/watch process, so newly added classes never make it into the final CSS.
Installing Tailwind as a regular dependency instead of a dev dependency.
Mixing Tailwind v3 @tailwind directives with v4-only import syntax after an incomplete upgrade.
Key Takeaways
A working Tailwind setup needs the package installed, a config file, and directives in a CSS entry file.
The content array must include every file type where you use Tailwind classes.
Most frameworks provide an official plugin that automates the wiring for you.
Tailwind v4 simplifies setup to a single @import "tailwindcss"; statement.
Always link the compiled CSS output, not the raw source file, in your HTML.
Pro Tip
If styles seem to be missing after adding new markup, check your content paths first. Ninety percent of "Tailwind isn't working" issues are misconfigured content globs.
You now know how to install and configure Tailwind CSS with npm. Next, learn the fastest way to try Tailwind using the CDN build, no installation required.