Kritim Yantra
Jun 27, 2025
Want to build beautiful, responsive Laravel applications quickly? Laravel 12 and TailwindCSS make it easier than ever to create stunning UIs without writing custom CSS.
In this guide, you’ll learn:
✔ How to set up TailwindCSS in Laravel 12
✔ Using Tailwind classes in Blade templates
✔ Best practices for structuring your styles
Perfect for beginners—let’s get started!
Before we begin, ensure you have:
✔ Laravel 12 installed (composer create-project laravel/laravel project-name
)
✔ Node.js 20+ (for TailwindCSS)
✔ Basic familiarity with Laravel Blade
Run these commands in your Laravel project:
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init
This installs Tailwind and generates a config file (tailwind.config.js
).
tailwind.config.js
Update the file to scan Blade templates:
module.exports = {
content: [
"./resources/**/*.blade.php",
"./resources/**/*.js",
],
theme: {
extend: {},
},
plugins: [],
}
Create or modify resources/css/app.css
:
@tailwind base;
@tailwind components;
@tailwind utilities;
Update vite.config.js
to process CSS:
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,
}),
],
});
In resources/views/welcome.blade.php
, add:
<!DOCTYPE html>
<html>
<head>
@vite(['resources/css/app.css'])
</head>
<body>
<!-- Your content here -->
</body>
</html>
npm run dev
Now Tailwind is ready!
Tailwind provides utility classes for styling. Let’s build a simple page.
Update welcome.blade.php
:
<!DOCTYPE html>
<html>
<head>
@vite(['resources/css/app.css'])
<title>Laravel + Tailwind</title>
</head>
<body class="bg-gray-100 min-h-screen">
<div class="container mx-auto p-8">
<h1 class="text-4xl font-bold text-blue-600 mb-6">
Welcome to Laravel 12 + Tailwind!
</h1>
<div class="bg-white p-6 rounded-lg shadow-md">
<p class="text-gray-700 mb-4">
This is a beginner-friendly guide to using TailwindCSS with Laravel Blade.
</p>
<button class="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded">
Get Started
</button>
</div>
</div>
</body>
</html>
Class | Effect |
---|---|
bg-gray-100 |
Light gray background |
min-h-screen |
Full viewport height |
container mx-auto |
Centered container |
text-4xl font-bold |
Large bold text |
rounded-lg shadow-md |
Card-like styling |
hover:bg-blue-600 |
Hover effect |
@apply
for Reusable StylesInstead of repeating classes, extract them in CSS:
.btn-primary {
@apply bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded;
}
Then use in Blade:
<button class="btn-primary">Click Me</button>
Avoid long class strings—use components or partials.
npm run build
This generates minified CSS.
✅ TailwindCSS integrates smoothly with Laravel Blade.
✅ Utility-first CSS speeds up development.
✅ Vite processes Tailwind efficiently.
✅ Use @apply
for reusable styles.
@tailwindcss/forms
)Happy styling! 🎨
Questions? Ask below! 👇
No comments yet. Be the first to comment!
Please log in to post a comment:
Sign in with Google