To leverage Tailwind CSS in modern frontend workflows, developers integrate it into build tools like Vite, Next.js (App Router), or standalone PostCSS build pipelines. In this guide, you will learn how Tailwind scans template files, configures content paths, and injects directives into global stylesheets.
1. Installation in a Vite (React/Vue) Project
1# 1. Install Tailwind, PostCSS & Autoprefixer
2npminstall-D tailwindcss postcss autoprefixer
3
4# 2. Generate configuration files
5npx tailwindcss init -p
This generates two files:
postcss.config.js
tailwind.config.js
2. Configuring Content Paths in tailwind.config.js
Tailwind's engine must know which files contain class names to purge unused styles:
1/** @type {import('tailwindcss').Config} */
2module.exports ={
3content:[
4"./index.html",
5"./src/**/*.{js,ts,jsx,tsx}",
6],
7theme:{
8extend:{
9colors:{
10brand:{
11light:'#38BDF8',
12DEFAULT:'#0284C7',
13dark:'#0369A1',
14}
15}
16},
17},
18plugins:[],
19}
Critical Rule: If you add a new directory (e.g., ./components/**/*.{jsx,tsx}) and forget to list it in content: [], Tailwind will NOT generate styles for those components!
3. Injecting Tailwind Directives
In your main stylesheet (src/index.css or app/globals.css), inject Tailwind's layers: