Introduction to Tailwind CSS in Laravel
Tailwind CSS is a modern utility-first CSS framework designed to speed up UI development. If you haven’t explored it yet, I’ve written a comprehensive guide to Tailwind CSS that’s perfect for beginners.
This tutorial walks you through integrating Tailwind CSS into any Laravel project, whether you’re starting fresh or adding it to an existing codebase.
Table of Contents
1. Create a New Laravel Project with Jetstream
If you're starting a fresh Laravel project and want Tailwind CSS pre-installed, Jetstream is the fastest option. It also sets up a JavaScript framework like Vue or React for you.
After this, Tailwind is ready to use out of the box.
2. Install Tailwind CSS in an Existing Laravel Project
For existing Laravel projects, use your preferred package manager to install Tailwind and its dependencies.
NPM:
Yarn:
Bun:
Tailwind is a PostCSS plugin, and it relies on
autoprefixer
for proper browser compatibility.
3. Publish Tailwind and PostCSS Configuration
Generate the Tailwind and PostCSS config files with:
NPM:
Yarn:
Bun:
You’ll get two files:
tailwind.config.js
postcss.config.js
4. Add Tailwind Directives to Your CSS File
Open or create the file at resources/css/app.css
And add the following:
Do not add
@tailwind variants;
— it’s deprecated and no longer needed.
5. Compile Assets Using Vite
Laravel uses Vite for fast asset bundling. Use these commands depending on your package manager:
Development:
Production:
The the dev
command supports hot-reloading; build
is for production-ready minified output.
Link Compiled CSS in Blade Templates
In your main Blade file (e.g., resources/views/layouts/app.blade.php
), include Tailwind using Laravel's @vite
directive:
7. Conclusion
That’s it! You’ve now integrated Tailwind CSS into your Laravel project. Whether you started from scratch with Jetstream or added it manually, you’re ready to build responsive, fast, and beautiful interfaces.
Now go build something amazing with Laravel + Tailwind!