Install Tailwind CSS with Laravel 11

Hello, laravel web developers! This article will show how to install tailwind CSS with laravel 11. Tailwind CSS is an open-source CSS framework. The main feature of this library is that, unlike other CSS frameworks like Bootstrap, it does not provide a series of predefined classes for elements such as buttons or tables.

The simplest and fastest way to get up and running with Tailwind CSS from scratch is with the Tailwind CLI tool.

Laravel 11 Install Tailwind CSS

Here, we'll see three ways to install Tailwind CSS in the Laravel application.

  1. Install Tailwind CSS using npm
  2. Install Tailwind CSS using Breeze
  3. Install Tailwind CSS using Jetstream

 

Install Tailwind CSS using npm

First, we'll install tailwind CSS using NPM.

Step 1: Install Laravel 11

In this step, we'll install laravel 11 using the following command.

composer create-project laravel/laravel example-app

 

Step 2: Install Tailwind CSS

Next, we'll install Tailwind CSS with the dependency and create the tailwind.config.js file using the following command.

npm install -D tailwindcss postcss autoprefixer
  
npx tailwindcss init

 

Step 3: Configure Template Path

Open the tailwind.config.js file and add the file paths there.

tailwind.config.js

export default {
  content: [
    "./resources/**/*.blade.php",
    "./resources/**/*.js",
    "./resources/**/*.vue",
  ],
  theme: {
    extend: {},
  },
  plugins: [
  ],
}

 

Step 4: Add Tailwind with Laravel mix

Now, open the vite.config.js file and add the following code to that file.

vite.config.js

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import tailwindcss from 'tailwindcss';

export default defineConfig({
    plugins: [
        laravel({
            input: ['resources/css/app.css', 'resources/js/app.js'],
            refresh: true,
        }),
    ],
    css: {
        postcss: {
          plugins: [tailwindcss()],
        },
    }
});

 

Step 5: Add Tailwind CSS in the app.css file

Next, we'll open the app.css file and add the following code to that file.

resources/css/app.css

@tailwind base;
@tailwind components;
@tailwind utilities;

 

Step 6: Install npm and Build

Then, we'll install npm and run the following code to that file.

npm install
npm run dev

 

Step 7: Use Tailwind CSS in App

Now, you can use Tailwind CSS in your Blade file.

resources/views/welcome.blade.php

<!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>
  <div class="container mx-auto px-10">
      <h1 class="text-3xl font-bold underline">
        Install Tailwind CSS with Laravel 11 - Techsolutionstuff
      </h1>
  
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
      tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
      quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
      consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
      cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat ncupidatat non
      proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
  </div>
</body>
</html>

 

Install Tailwind CSS using Breeze

Next, we'll install tailwind CSS using Breeze.

Step 1: Install Breeze

Now, run the install laravel breeze package using the following command.

composer require laravel/breeze --dev

Then, install Laravel Breeze for basic auth scaffolding using the following command.

php artisan breeze:install

Next, run the npm install using the following command.

npm install 
  
npm run dev

 

Install Tailwind CSS using Jetstream

Now, we'll install tailwind CSS using Jetstream.

Step 1: Install Jetstream

In this step, we'll install the jetstream using the composer command.

composer require laravel/jetstream

 

Step 2: Create Auth with Livewire

Next, we'll create authentication using the following command. You can create basic login, register, and email verification.

php artisan jetstream:install livewire
  
OR
  
php artisan jetstream:install livewire --teams

Now, install npm using the below command

npm install

let's run the package:

npm run dev

 


You might also like :

techsolutionstuff

Techsolutionstuff | The Complete Guide

I'm a software engineer and the founder of techsolutionstuff.com. Hailing from India, I craft articles, tutorials, tricks, and tips to aid developers. Explore Laravel, PHP, MySQL, jQuery, Bootstrap, Node.js, Vue.js, and AngularJS in our tech stack.

RECOMMENDED POSTS

FEATURE POSTS