TExcelTAD
Home › Tailwind CSS › Tailwind Get Started

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.

html · try it yourself
<!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:

html · try it yourself
<!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:

bash · try it yourself
npm install tailwindcss @tailwindcss/vite
added 18 packages, and audited 32 packages in 3s

found 0 vulnerabilities

Register the plugin in vite.config.js:

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:

css
/* 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:

bash · try it yourself
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:

js
// 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?

  1. @tailwind utilities;
  2. @import "tailwindcss";
  3. @use tailwind;
  4. @layer tailwind;

Which package provides the official Vite integration?

  1. tailwind-vite
  2. @tailwindcss/vite
  3. vite-plugin-css
  4. @vitejs/tailwind

How do you add custom theme values when using the browser build?

  1. A <script type="tailwind-config"> tag
  2. A <style type="text/tailwindcss"> block with @theme
  3. A data-theme attribute on <html>
  4. It is not possible