Introduction
Tailwind CSS 4.0 is a huge evolution of Tailwind β cleaner, faster, and more modern. The new version removes older configs, simplifies setup, and introduces the powerfulβcontent-aware engineβ that scans your project automatically. β‘ This tutorial will walk you through everything you need to know!
Key Highlights of Tailwind 4 β¨
- No config file required (but optional) π§
- No PostCSS setup required β‘
- New @import "tailwindcss" syntax π
- Faster builds with the new engine π
- Automatic class detection β no βcontentβ array π―
- Better theme extensions & CSS nesting support π
Installation & Setup π§
1. Install Tailwind 4
Tailwind 4 works with ANY framework β React, Vite, Next.js, Vue, Laravel, or plain HTML.
Install Tailwind
npm install tailwindcssNote
2. Add Tailwind to Your CSS File
Create styles.css (or any CSS file) and add:
styles.css
@import "tailwindcss";3. Import Your CSS File
This depends on your project type.
Example for Vite / React:
main.jsx
import './styles.css'Example for HTML:
<link rel="stylesheet" href="styles.css" />Using Tailwind 4 Classes π¨
Tailwind 4 uses the same class-based styling you're already familiar with.
Example Component
export default function App() {
return (
<div className="bg-blue-600 text-white p-10 text-center text-3xl font-bold rounded-2xl">
Tailwind 4 is AMAZING! π
</div>
);
}New Changes in Tailwind 4 (Important!) π
1. New Import Syntax
Old version used:
Old Tailwind
@tailwind base;
@tailwind components;
@tailwind utilities;Tailwind 4 uses:
New Tailwind 4
@import "tailwindcss";2. No config file needed
The default theme works instantly. But if you want to customize, create:
Create config
npx tailwindcss initYour tailwind.config.js may look like:
tailwind.config.js
export default {
theme: {
extend: {
colors: {
brand: "#6366f1",
},
},
},
};3. CSS Nesting Built-In
CSS Nesting Example
.btn {
@apply px-4 py-2 bg-black text-white;
&:hover {
@apply bg-gray-800;
}
}Tailwind 4 Folder Structure (Example) π
| File | Description |
|---|---|
| styles.css | Main file importing Tailwind |
| tailwind.config.js | (Optional) Custom theme setup |
| index.html / App.jsx | Where you use Tailwind classes |
Testing Tailwind 4 π―
Try adding this HTML:
HTML Test
<div class="p-8 bg-emerald-500 text-white text-2xl rounded-xl shadow-lg">
Tailwind 4 is working! π
</div>