0Pricing
Tailwind CSS Academy · Lesson

Installing and Configuring Tailwind

Set up Tailwind CSS via CDN and via npm with the CLI, and see your first styled HTML page come to life.

Installing and Configuring Tailwind is a free Tailwind CSS Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Tailwind CSS Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Two Ways to Add Tailwind

Two ways to add Tailwind: a CDN script tag for quick prototyping, or the npm CLI for production, which builds a tiny optimized CSS file.

<!-- CDN approach (prototyping only) -->
<script src="https://cdn.tailwindcss.com"></script>

Installing Tailwind via npm

For production, install via npm: tailwindcss, postcss, and autoprefixer. Then run npx tailwindcss init -p to create both config files at once.

npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p

The tailwind.config.js File

The tailwind.config.js file has one key field to set first: content. List every file that uses Tailwind classes, or those classes get left out of your build.

// tailwind.config.js
module.exports = {
  content: [
    './index.html',
    './src/**/*.{html,js,jsx,ts,tsx,vue,svelte}',
  ],
  theme: {
    extend: {},
  },
  plugins: [],
};

The PostCSS Config File

Tailwind runs as a PostCSS plugin. The postcss.config.js file tells your bundler to run it. Most tools pick it up automatically — you rarely touch it again.

// postcss.config.js
module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  },
};

Creating Your Main CSS File

Make a CSS entry file and add the three @tailwind directives: base, components, and utilities. At build time they expand into Tailwind generated styles.

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

Running the Tailwind CLI

The Tailwind CLI watches your files and rebuilds on save. Point --input and --output at your files, add --watch for dev, and --minify for production.

# Development (with watch)
npx tailwindcss -i ./src/input.css -o ./dist/output.css --watch

# Production (minified)
npx tailwindcss -i ./src/input.css -o ./dist/output.css --minify

Linking the CSS in HTML

Now link the generated CSS in your HTML like any stylesheet. Point href at the output file, not the input, and every utility class starts working.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <link href="./dist/output.css" rel="stylesheet" />
  <title>My Tailwind Site</title>
</head>
<body>
  <h1 class="text-3xl font-bold text-blue-600">Hello Tailwind!</h1>
</body>
</html>

Tailwind With Vite

Using Vite? Tailwind plugs in through PostCSS. Set up the configs, import your CSS in main.js, and Vite handles the rest with instant hot reloading.

// main.js (Vite entry point)
import './src/input.css';

// Then run:
npm run dev

Tailwind With Create React App

On Create React App, install the packages, init the config, and import index.css with the directives. CRA already runs PostCSS, so just restart the server.

# 1. Install dependencies
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p

# 2. Add directives to src/index.css
# @tailwind base;
# @tailwind components;
# @tailwind utilities;

# 3. Start dev server
npm start

Tailwind Preflight: The CSS Reset

The @tailwind base line injects Preflight, a gentle reset. It clears default margins, sets box-sizing everywhere, and gives you a clean, consistent baseline.

/* Preflight effects (auto-applied): */
/* - All elements: box-sizing: border-box */
/* - Body: margin: 0 */
/* - h1-h6: font-size/weight reset to body defaults */
/* - ul/ol: list-style: none; margin: 0; padding: 0 */

Verifying Your Installation

To verify it works, add text-3xl font-bold text-indigo-600 to a heading. Big, bold, indigo? You are set. If not, check your content paths in the config.

<!-- Verification test -->
<h1 class="text-3xl font-bold text-indigo-600">
  If this is big, bold, and purple — Tailwind is working!
</h1>

Quick Check

Quick check! Make sure setup clicked. 🛠️

Lesson Recap

Great! Add Tailwind via CDN or npm, set content paths so classes ship, and add the three @tailwind directives. Next up: building your first page.

Frequently asked questions

Is the “Installing and Configuring Tailwind” lesson free?

Yes — the full text of “Installing and Configuring Tailwind” is free to read here on the web, and the Tailwind CSS Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Tailwind CSS Academy course, upgrade to CoddyKit PRO.

What will I learn in “Installing and Configuring Tailwind”?

Set up Tailwind CSS via CDN and via npm with the CLI, and see your first styled HTML page come to life. You practise Tailwind CSS Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Tailwind CSS Academy?

No prior experience is required. Tailwind CSS Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Installing and Configuring Tailwind” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Tailwind CSS Academy lesson?

Yes. Every Tailwind CSS Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Utility-First CSS Explained
  2. Installing and Configuring Tailwind
  3. Your First Tailwind Page
  4. Tailwind vs Traditional CSS
← Back to Tailwind CSS Academy