Tailwind CSS Get Started
There are two common ways to start using Tailwind CSS: a quick CDN script for learning, and an npm install for real projects.
Option 1: The Play CDN (for Learning)
Add one <script> tag to the <head> of any HTML page. The script reads the classes in your page and creates the CSS for them in the browser.
Example
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>A complete page looks like this:
Example
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My Tailwind Page</title>
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
</head>
<body class="p-8">
<h1 class="text-3xl font-bold text-cyan-600">It works!</h1>
<p class="mt-3 text-gray-600">Tailwind is loaded from the CDN.</p>
</body>
</html>Try it Yourself »This is what every example in this tutorial uses, so they run in the Try it editor.
The Play CDN is great for learning and quick demos, but it is not meant for live websites. It builds the CSS in each visitor's browser, which is slower. For a real site, use the npm setup below.
Option 2: Install with npm and Vite
For real websites, Tailwind runs on your computer and creates a small CSS file with only the classes you use. You need Node.js installed.
Step 1: Create a project
Example
npm create vite@latest my-shop
cd my-shop
npm installStep 2: Install Tailwind
Example
npm install tailwindcss @tailwindcss/viteStep 3: Add the plugin to vite.config.js
Example
import { defineConfig } from "vite";
import tailwindcss from "@tailwindcss/vite";
export default defineConfig({
plugins: [tailwindcss()],
});Step 4: Import Tailwind in your CSS file
Example
@import "tailwindcss";Step 5: Start the dev server
Example
npm run devNow you can use Tailwind classes in your HTML, and the page updates every time you save.
Adding Your Own Colours
Tailwind lets you add your own theme values with @theme. With the Play CDN, put it inside a <style type="text/tailwindcss"> tag. Each --color-... variable becomes a new colour class.
Example
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
<style type="text/tailwindcss">
@theme {
--color-brand: #0f766e;
--color-brand-light: #ccfbf1;
}
</style>
</head>
<body class="p-8">
<div class="bg-brand-light text-brand p-6 rounded-lg font-semibold">
Ali Electronics uses its own brand colours.
</div>
</body>
</html>Try it Yourself »The variable --color-brand created the classes bg-brand, text-brand, border-brand and more.
Which Option to Choose?
| Play CDN | npm install |
|---|---|
| One line, nothing to install | Needs Node.js and a build tool |
| Good for learning and demos | Good for real websites |
| CSS made in the browser (slower) | Small, fast CSS file made in advance |
Editor Tip
Install the Tailwind CSS IntelliSense extension in VS Code. It suggests class names while you type and shows the CSS each class adds when you hover over it.
Exercise
Exercise
Which line in a CSS file loads Tailwind CSS version 4 in an npm project?
