Lesson 2
15 min
Install Tailwind with Vite, the CDN, or a framework like Astro.
Definition
Installing Tailwind CSS means adding Tailwind to a project so that its utility classes become usable in your HTML. In practice, you install the tailwindcss package along with a build plugin (such as @tailwindcss/vite), which scans your code and generates only the CSS you need, or you load the Play CDN directly for a simple prototype.
There are several ways to install Tailwind depending on your project. In this lesson, we cover the two most common methods: installation with a build tool (Vite, the recommended method for a real project) and quick integration through a CDN link to test or prototype rapidly.
Whichever method you choose, the result is the same: you will be able to write classes like p-4 or bg-blue-500 in your HTML and see them applied immediately in the browser.
For the build-tool method, you only need three things on your machine:
You can check your versions with these two commands:
node --version
npm --versionSince version 4, Tailwind can be installed with just a few commands, with no mandatory configuration file. Here are the steps to follow for a Vite-based project:
# 1. Create an empty Vite project (if needed)
npm create vite@latest my-project
cd my-project
# 2. Install the required packages
npm install tailwindcss @tailwindcss/viteIf you are starting from scratch, create the Vite project first, then install Tailwind inside the folder that was created. The order matters: the packages must be added inside your project folder, where thepackage.json file is located.
Next, enable the Tailwind plugin in your Vite configuration:
import { defineConfig } from 'vite'
import tailwindcss from '@tailwindcss/vite'
export default defineConfig({
plugins: [
tailwindcss(),
],
})Then import Tailwind in your main CSS file (for examplesrc/style.css):
@import "tailwindcss";This single line is enough: Tailwind itself injects its base styles (Preflight), its theme variables and all the utility classes you will need.
All that is left is to import this CSS file in your HTML or JavaScript entry point, then start your development server:
npm run devVite then displays a local address (usuallyhttp://localhost:5173). As long as the server is running, every change to your classes is reflected instantly in the browser, with no manual reload.
If you simply want to test an idea in a single HTML file, without a build tool, you can use the Play CDN script. This method is handy for learning or building a demo, but it is not recommended in production (heavier file, no advanced theme customization).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
</head>
<body>
<h1 class="text-3xl font-bold text-indigo-600">
Hello Tailwind!
</h1>
</body>
</html>To try it, save this code in an index.html file and open it directly in your browser: no installation, no terminal, no server. This is what makes the CDN ideal for a first contact or for sharing a small example.
Here is why the CDN remains reserved for experiments:

Once Method 1 is complete, your project contains a few key files. Thepackage.json file lists the installed packages, and you will find Tailwind and its Vite plugin in the dependencies:
{
"dependencies": {
"tailwindcss": "^4.0.0",
"@tailwindcss/vite": "^4.0.0"
}
}The version numbers may differ on your machine: this is not a problem as long as you stay on version 4. You do not need to create atailwind.config.js file to get started; it only becomes useful later, when you want to customize your theme.
The choice simply depends on what you want to do. Here is a quick guide:
Most modern frameworks offer their own official integration. The principle remains the same: install the matching package, enable the plugin, then import Tailwind in the global CSS.
npx astro add tailwind configures everything automatically.create-next-app.In every case, remember to check Tailwind's official documentation: it provides an installation guide for each framework and remains the most up-to-date source if a command changes.
Once Tailwind is installed, the best way to check that everything is properly wired up is to add a very visible class to an element, such asbg-red-500 or text-4xl, and reload the page. If the style is applied, the installation was successful.
If nothing changes, don't worry: open your browser's developer tools (the F12 key), then look in the "Console" and "Network" tabs to see whether an error appears or your CSS file is not loaded. This almost always points you in the right direction.
This is the most common problem for a beginner, and it almost always comes from a simple oversight. Go through these points:
src/style.css is actually imported in your HTML or JavaScript entry file.tailwindcss() appears in the plugins list ofvite.config.js.npm run dev again.Your turn
<h1> heading with the classestext-4xl font-extrabold text-blue-600 text-center mt-10. Check in your browser that the heading appears centered, in blue and large.