Content Configuration for Purging
You'll learn how to tell Tailwind which files to scan so it can remove unused CSS from your production builds.
Why Purging Matters
Tailwind CSS generates thousands of utility classes by default—far more than any single project will use. Without purging, your CSS bundle could be several megabytes! Purging scans your project files, identifies which Tailwind classes you actually use, and strips out everything else. The result? A tiny, production-ready CSS file.
Think of it like packing for a trip: Tailwind brings the entire wardrobe, but purging ensures you only pack the clothes you'll actually wear.
Configuring the Content Array
In your tailwind.config.js file, the content array tells Tailwind where to look for class names:
module.exports = {
content: [
'./src/**/*.{html,js}',
'./public/index.html',
],
theme: {
extend: {},
},
plugins: [],
}
What This Means
'./src/**/*.{html,js}'— Scan all HTML and JavaScript files in thesrcfolder and its subfolders- The
**wildcard means "any subdirectory" - The
*.{html,js}pattern matches files ending in.htmlor.js
Common Patterns
You might need different patterns depending on your framework:
content: [
'./pages/**/*.{js,jsx}', // Next.js pages
'./components/**/*.{js,jsx}', // React components
'./index.html', // Single HTML file
]
Key Takeaway: The content array in your Tailwind config file tells the build process which files to scan for class names, ensuring only the CSS you actually use makes it to production.