Adding Tailwind: Play CDN vs Build

Two ways to add Tailwind to a project and when to use each.

Syntax<script src="https://cdn.tailwindcss.com"></script>

There are two common ways to use Tailwind.

1. The Play CDN (fastest to start)

Add one <script> tag to your page. Tailwind then reads your classes in the browser. Great for learning, demos, and this tutorial.

2. A build step (for real projects)

Install Tailwind with npm and run its build tool. It scans your files and outputs a small, optimized CSS file with only the classes you actually used.

Play CDNBuild step
No installNeeds npm
Larger downloadTiny final CSS
PrototypingProduction

Example

Try it yourself
Loading editor…
Press Run to see the result.

When to use it

  • A developer quickly tests Tailwind ideas in a plain HTML file by dropping in the Play CDN script tag without any build tooling.
  • A production Next.js app integrates Tailwind via the npm package and PostCSS to enable tree-shaking and a minimal CSS bundle.
  • A tutorial author uses the CDN version for interactive code demos so students can run examples without installing Node.js.

More examples

Play CDN one-liner

A single script tag loads Tailwind via the Play CDN, enabling all utility classes in a plain HTML file with zero build steps.

Example Β· html
<!DOCTYPE html>
<html>
<head>
  <script src="https://cdn.tailwindcss.com"></script>
</head>
<body>
  <h1 class="text-3xl font-bold text-indigo-600">Hello CDN!</h1>
</body>
</html>

Install via npm

The npm install sets up Tailwind and its PostCSS pipeline; init -p generates both tailwind.config.js and postcss.config.js.

Example Β· bash
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p

Entry CSS with directives

The three @tailwind directives inject Tailwind's base reset, component layer, and utility classes into the compiled CSS output.

Example Β· css
/* src/input.css */
@tailwind base;
@tailwind components;
@tailwind utilities;

Discussion

  • Be the first to comment on this lesson.
Adding Tailwind: Play CDN vs Build β€” Tailwind CSS | SoundsCode