Tailwind Get Started
There are two common ways to use Tailwind CSS v4:
| Option | Best for | How it works |
|---|---|---|
Browser build (CDN <script>) |
Learning, quick prototypes, demos | Compiles classes in the browser at runtime |
| Build tool (Vite plugin, PostCSS or CLI) | Real websites and apps | Scans your files and writes a small static CSS file |
Option 1 — the browser build
Add one <script> tag to the <head> and you can use every utility immediately. This is exactly what the playgrounds in this course do.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
</head>
<body class="p-6">
<h1 class="text-3xl font-bold text-emerald-600 underline decoration-wavy">
It works!
</h1>
<p class="mt-2 text-gray-600">Tailwind compiled this page in your browser.</p>
</body>
</html>To customise Tailwind with the browser build, add a <style> block with type="text/tailwindcss". Inside it you can use Tailwind directives such as @theme:
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
<style type="text/tailwindcss">
@theme {
--color-brand: #ff6b35;
}
</style>
</head>
<body class="p-6">
<p class="rounded-lg bg-brand px-4 py-3 font-semibold text-white">
bg-brand is a colour I defined myself.
</p>
</body>
</html>Note: The browser build is not meant for production: it downloads the compiler to every visitor and generates CSS on each page load. Use a build step for real sites.
Option 2 — Vite (recommended for projects)
Tailwind ships an official Vite plugin, @tailwindcss/vite. Start from a Vite project and install two packages:
npm install tailwindcss @tailwindcss/viteadded 18 packages, and audited 32 packages in 3s
found 0 vulnerabilities
Register the plugin in vite.config.js:
import { defineConfig } from 'vite';
import tailwindcss from '@tailwindcss/vite';
export default defineConfig({
plugins: [tailwindcss()],
});Then import Tailwind at the top of your main CSS file — this single line replaces the three @tailwind base/components/utilities directives from v3:
/* src/style.css */
@import "tailwindcss";Make sure the CSS is loaded (for example import './style.css' in main.js), start the dev server and use classes in your HTML:
npm run dev VITE v7.0.4 ready in 312 ms
➜ Local: http://localhost:5173/
➜ Network: use --host to expose
Tailwind automatically detects your source files (it skips .gitignored paths and node_modules), so there is no content array to configure as there was in v3.
Other installation options
| Tool | Packages | Setup |
|---|---|---|
| Vite | tailwindcss @tailwindcss/vite |
plugins: [tailwindcss()] |
| PostCSS (Next.js, webpack…) | tailwindcss @tailwindcss/postcss |
plugins: { "@tailwindcss/postcss": {} } in postcss.config.mjs |
| Standalone CLI | tailwindcss @tailwindcss/cli |
npx @tailwindcss/cli -i input.css -o output.css --watch |
A PostCSS config looks like this:
// postcss.config.mjs
export default {
plugins: {
"@tailwindcss/postcss": {},
},
};Coming from v3?
| v3 | v4 |
|---|---|
@tailwind base; @tailwind components; @tailwind utilities; |
@import "tailwindcss"; |
tailwind.config.js with theme.extend |
@theme { … } in CSS |
content: ["./src/**/*.html"] |
automatic detection (add extra paths with @source) |
tailwindcss PostCSS plugin |
@tailwindcss/postcss |
npx tailwindcss CLI |
npx @tailwindcss/cli |
Tip: An official upgrade tool,
npx @tailwindcss/upgrade, migrates most of a v3 project automatically.
Test yourself
Which line loads Tailwind in a v4 CSS file?
@tailwind utilities;@import "tailwindcss";@use tailwind;@layer tailwind;
Which package provides the official Vite integration?
tailwind-vite@tailwindcss/vitevite-plugin-css@vitejs/tailwind
How do you add custom theme values when using the browser build?
- A
<script type="tailwind-config">tag - A
<style type="text/tailwindcss">block with@theme - A
data-themeattribute on<html> - It is not possible