Master Code
On The Go

Learn. Practice. Build.

Home › How-To › Install Tailwind CSS

Tailwind CSS Guide

How to Install Tailwind CSS

Setup Tailwind v4 with Vite, Next.js, or PostCSS in under 10 minutes.

Last updated: October 2026 · Tested on Tailwind v4.0

Quick answer: Run npm install tailwindcss @tailwindcss/vite (or @tailwindcss/postcss), add the Tailwind plugin to your build config, then add @import "tailwindcss"; to your main CSS file. No tailwind.config.js is needed in v4.

1

What's New in Tailwind v4

Tailwind v4 is a major rewrite. The biggest changes:

  • No more tailwind.config.js — configuration happens in CSS.
  • Faster build times — up to 5x faster.
  • Smaller output — unused styles are removed automatically.
  • Native CSS variables — theme tokens are accessible as CSS variables.
  • Simpler setup — just one import and one plugin.
2

Option A: Install with Vite

If you're using Vite (recommended for React, Vue, and Svelte projects):

# Install Tailwind and the Vite plugin
npm install tailwindcss @tailwindcss/vite

Add the plugin to your vite.config.js:

import { defineConfig } from 'vite';
import tailwindcss from '@tailwindcss/vite';

export default defineConfig({
    plugins: [
        tailwindcss(),
    ],
});

Add the import to your main CSS file (e.g., src/index.css):

@import "tailwindcss";

That's it. Start using utility classes in your components.

3

Option B: Install with Next.js

For a new Next.js app, the easiest way is to let create-next-app do it:

npx create-next-app@latest my-app

When prompted, answer Yes to "Would you like to use Tailwind CSS?"

For an existing Next.js project:

# Install Tailwind and PostCSS plugin
npm install tailwindcss @tailwindcss/postcss postcss

Create a postcss.config.mjs file:

const config = {
    plugins: {
        "@tailwindcss/postcss": {},
    },
};

export default config;

Add the import to app/globals.css:

@import "tailwindcss";
4

Option C: Install with PostCSS (Any Framework)

For frameworks without a dedicated Tailwind plugin (Webpack, Parcel, etc.):

npm install tailwindcss @tailwindcss/postcss postcss

Create postcss.config.js:

module.exports = {
    plugins: {
        "@tailwindcss/postcss": {},
    },
};

Import Tailwind in your CSS:

@import "tailwindcss";
5

Verify the Installation

Add a test element to make sure everything works:

<div class="bg-blue-500 text-white p-4 rounded-lg">
    If you see blue, Tailwind is working!
</div>

If the styles apply, you're done. If not, check the troubleshooting section below.

6

Customize Your Theme in CSS (v4)

In Tailwind v4, you customize the theme directly in CSS using @theme:

@import "tailwindcss";

@theme {
    --color-brand: #3b82f6;
    --color-brand-dark: #1e40af;
    --font-display: "Inter", sans-serif;
    --spacing-128: 32rem;
}

Now you can use bg-brand, text-brand-dark, font-display, and p-128 in your HTML. No config file needed.

💡 Why this is better: Native CSS variables mean your theme values are available anywhere in your CSS, not just in Tailwind utility classes. You can use them in custom CSS, animations, and even inline styles.

🐛 Troubleshooting Common Errors

Styles not applying at all

Check that:

  • @import "tailwindcss"; is at the top of your CSS file.
  • The plugin is added to your Vite/PostCSS config.
  • Your CSS file is imported in your entry point (e.g., main.jsx or layout.tsx).
  • You restarted the dev server after installing.

"Cannot find module '@tailwindcss/vite'"

You're using the wrong plugin. For Vite, install @tailwindcss/vite. For PostCSS, install @tailwindcss/postcss. Do not use both.

Custom classes not working

In v4, custom colors and utilities must be defined inside @theme { } or @utility { }. Defining them in :root won't generate utility classes.

Upgrading from v3? The migration is not automatic. The tailwind.config.js file is gone, and many class names have changed. Use the official upgrade tool: npx @tailwindcss/upgrade@next.

📦 Project-Specific Tips

❓ Frequently Asked Questions

How do I install Tailwind CSS?

Install Tailwind via npm (npm install tailwindcss @tailwindcss/vite or @tailwindcss/postcss), add the plugin to your build tool config, and import Tailwind in your CSS file with @import 'tailwindcss'.

Does Tailwind v4 need a config file?

No. Tailwind v4 eliminates the tailwind.config.js file. You configure your theme directly in CSS using the @theme directive.

Can I use Tailwind CSS with Next.js?;

Yes. Next.js supports Tailwind CSS out of the box. When you create a new Next.js app, select Tailwind CSS during setup and it will be configured automatically.

Why is my Tailwind CSS not working?

Common causes: missing the @import 'tailwindcss' in your CSS file, incorrect content paths (v3), not adding the plugin to your build tool, or forgetting to restart the dev server.

Is Tailwind CSS free?

Yes. Tailwind CSS is free and open source under the MIT license. Tailwind Plus (formerly Tailwind UI) is a paid component library, but the framework itself is completely free.

🎯 What's Next?

← All How-To Guides