Installation
Setting up Tailwind CSS in a Laravel project.
Start by creating a new Laravel project if you don’t have one set up already. The most common approach is to use the Laravel installer.
laravel new my-projectcd my-projectInstall @tailwindcss/vite and its peer dependencies via npm.
npm install tailwindcss @tailwindcss/viteAdd the @tailwindcss/vite plugin to your Vite configuration.
import { defineConfig } from 'vite'import tailwindcss from '@tailwindcss/vite'export default defineConfig({ plugins: [ tailwindcss(), // … ],})Add an @import to ./resources/css/app.css that imports Tailwind CSS. Additionally, tell Tailwind CSS to scan some directories for utilities.
@import 'tailwindcss';@source '../../vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php';@source '../../storage/framework/views/*.php';@source '../**/*.blade.php';@source '../**/*.js';Run your build process with npm run dev.
npm run devMake sure your compiled CSS is included in the <head> then start using Tailwind’s utility classes to style your content.
<!doctype html><html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> @vite('resources/css/app.css') </head> <body> <h1 class="text-3xl font-bold underline"> Hello world! </h1> </body></html>