Are you tired of wrestling with ever-growing CSS files, obscure class names, and furious overrides when working with Laravel and Blade? The template engine is powerful, but without a utility-first CSS framework you spend more time writing custom rules than building interfaces. We, at Meteora Web, have integrated Tailwind CSS into dozens of Laravel projects — from proprietary platforms to complex e-commerce systems — and we've seen that the real gain is not just in development speed but in maintenance and deployment costs. This guide takes you step by step from basic setup to production build optimization.
Why combine Tailwind CSS with Laravel Blade?
Blade lets you write expressive templates with inherited layouts, sections, and components. Tailwind gives you a vocabulary of utility classes that integrate seamlessly with that structure. The result? Coherent interfaces without a single custom stylesheet. In a real project we followed — a management system for a clothing store — we reduced CSS code by 70% switching from Bootstrap to Tailwind on Laravel. Blade components become atomically clear: every class says exactly what it does.
How to install Tailwind CSS in a Laravel project?
Laravel 9 and above use Vite for bundling, not Laravel Mix anymore. The process has changed but is leaner. Here are the steps for a clean install.
Sponsored Protocol
1. Create a new Laravel project
composer create-project laravel/laravel my-project
cd my-project
2. Install Tailwind CSS and required plugins
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
This generates tailwind.config.js and postcss.config.js. Note: Laravel already includes postcss and autoprefixer in vite.config.js, but installing them explicitly avoids version conflicts.
3. Configure template paths
Edit tailwind.config.js to tell Tailwind where to look for used classes:
export default {
content: [
'./resources//*.blade.php',
'./resources//*.js',
'./resources/**/*.vue',
],
theme: {
extend: {},
},
plugins: [],
}
The content array is critical for production purging. If you forget to include your component folders, Tailwind will remove classes you use.
4. Add Tailwind directives to your CSS
In resources/css/app.css:
@tailwind base;
@tailwind components;
@tailwind utilities;
5. Configure Vite to process the CSS
Make sure vite.config.js points to the correct file:
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig({
plugins: [
laravel({
input: ['resources/css/app.css', 'resources/js/app.js'],
refresh: true,
}),
],
});
6. Build and verify
npm run build
php artisan serve
Load a Blade view with some Tailwind classes (e.g., class="text-red-500 font-bold") and check that the style appears. No manual compilation — Tailwind does everything automatically.
Sponsored Protocol
How to configure tailwind.config.js for a Laravel project?
Configuration goes beyond content. Here's how to use it to keep consistency with your project's design system.
Extend the theme with brand colors
theme: {
extend: {
colors: {
brand: {
50: '#f0f9ff',
100: '#e0f2fe',
// ... up to 950
},
},
fontFamily: {
sans: ['Inter', 'sans-serif'],
},
},
},
Now you can write bg-brand-500 in Blade without remembering hex codes. We always do this: client changes palette? One modification updates everything.
Add useful plugins
For forms, typography, etc.: @tailwindcss/forms and @tailwindcss/typography are our go-tos.
npm install -D @tailwindcss/forms @tailwindcss/typography
Then in config:
plugins: [
require('@tailwindcss/forms'),
require('@tailwindcss/typography'),
],
How to use Tailwind in Blade templates without cluttering markup?
The common objection: "Too many classes in the template make the markup unreadable." The practical solution is to create Blade components or use @apply directives and custom classes in CSS. We prefer components for reusability and maintainability.
Sponsored Protocol
Create a Button component
@props(['variant' => 'primary', 'size' => 'md'])
In the template you use . Clean, readable, and all styling logic is encapsulated.
When to use @apply
If you have a combination of classes that repeats identically in multiple places, extract it into a custom class:
/* resources/css/app.css */
@layer components {
.card-default {
@apply bg-white rounded-lg shadow-md p-6;
}
}
Then in Blade: class="card-default". But beware: overusing @apply nullifies the utility advantage — use it only for truly repetitive patterns.
How to optimize production builds with Laravel and Vite?
Tailwind by default includes only the classes found in the content files. In development it uses Just-in-Time (JIT) mode, so builds are light even locally. For production, there are extra tweaks.
Sponsored Protocol
Automatic purging with the content array
The content array you configured is already the main optimization. Tailwind scans the files and outputs CSS containing only the classes actually used. If you have dynamically generated classes (e.g., class="{{ $classString }}"), Tailwind can't detect them. Solution: use static classes or add a comment with all possible variants.
{{-- Possible classes: bg-red-500 bg-blue-500 bg-green-500 --}}
Automatic minification in production
Vite with the Laravel plugin already produces minified assets on npm run build. No extra configuration needed. To verify, open public/build/assets/app-*.css and you'll see compressed CSS.
Enable purging cache
With Tailwind 3.x, you can force cache regeneration with:
php artisan view:clear && npm run build
In CI/CD environments, use npm ci instead of npm install to lock versions.
Which mistakes to avoid when configuring Tailwind with Laravel?
After working on dozens of projects, we've collected the 3 most common errors:
- Forgetting to include Blade component directories — if you use Laravel components in
resources/views/components,./resources/**/*.blade.phpcovers them. But if you put them elsewhere (e.g.,app/View/Components), update thecontentarray. - Using dynamic classes generated by PHP — Tailwind doesn't run PHP; it can't anticipate
class="bg-{{ $color }}-500"if$coloris a variable. Write all possible combinations in an array and use a component withmatch. - Installing old Tailwind versions with Laravel Mix — For new projects use Vite. If you need to migrate an existing project on Laravel Mix, it's doable but requires attention to PostCSS conflicts. We covered this in our Tailwind CSS for Modern UI article.
What to do next?
You don't need anything else to get started. Here are the concrete actions to take right now:
Sponsored Protocol
- Open your Laravel project (or create a new one).
- Follow the installation steps above until you see a Tailwind color in a view.
- Configure
tailwind.config.jswith your brand colors and theformsandtypographyplugins. - Rewrite an existing Blade component (e.g., a button) using Tailwind utility classes and Blade components.
- Run
npm run buildand check the size of the generated CSS — ideally under 50 KB for medium projects. - If you run into issues, consult the official Tailwind Laravel guide.
We, at Meteora Web, use this setup every day. It works, it's maintainable, and clients notice the difference in site speed and design consistency. If you have a Laravel project you'd like to optimize with Tailwind, contact us — we know how to do it without waste.