How To Install Tailwind CSS In Laravel 9

Websolutionstuff | Jun-13-2022 | Categories : Laravel CSS

In this article, we will see how to install tailwind CSS in laravel 9. Tailwind CSS works by scanning all of your HTML files, JavaScript components, and any other templates for class names, generating the corresponding styles and then writing them to a static CSS file. It's fast, flexible, and reliable — with zero runtime.

So, let's see how to install tailwind css in laravel 9, install tailwind in laravel 9, laravel tailwind css, laravel breeze tailwind, tailwind laravel mix, laravel 9 tailwind css install, install tailwind css via npm, install tailwind css with jetstream, laravel 9 breeze install tailwind css.

 

Step 1: Install Laravel

In this step, we will install the laravel app using the below command.

composer create-project laravel/laravel new-app

 

 

Step 2: Install Tailwind CSS

Now, we will install CSS using the below command.

npm install -D tailwindcss

npx tailwindcss init

 

Step 3: Configure Template Path

Add the paths to all of your template files in your tailwind.config.js file.

module.exports = {
  content: ["./src/**/*.{blade.php,html,js}"],
  theme: {
    extend: {},
  },
  plugins: [],
}

 

Step 4: Add Tailwind with Laravel mix

Now, open the webpack.mix.js file and add lines there.

const mix = require('laravel-mix');
  
/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel applications. By default, we are compiling the CSS
 | file for the application as well as bundling up all the JS files.
 |
 */
  
mix.js("resources/js/app.js", "public/js")
.postCss("resources/css/app.css", "public/css", [
  require("tailwindcss"),
]);

 

 

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

Add the @tailwind directives for each of Tailwind’s layers to your main CSS file.

resources/css/app.css

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

 

Step 6: Install npm and Build

Now, run the npm install command and then build it with the npm run watch command.

npm install

Build npm process.

npm run watch

 

 

Step 7: Use Tailwind CSS in App

Now, you can use CSS in the blade file.

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link href="{{ asset('css/app.css') }}" rel="stylesheet">
</head>
<body>
  <div class="container mx-auto px-10">
      <h1 class="text-3xl font-bold underline">
        How To Install Tailwind CSS In Laravel 9 - Websolutionstuff
      </h1>
  
      <p> Hello world! </p>
  </div>
</body>
</html>

 


You might also like:

Recommended Post
Featured Post
How To Validate Password And Confirm Password In React JS
How To Validate Password And C...

In this article, we will see how to validate password and confirm password in react js. Sometimes we need to add th...

Read More

Sep-14-2022

How To Get Last 7 Days Record In Laravel 8
How To Get Last 7 Days Record...

In this example, we will see how to get the last 7 days record in laravel 8. You can simply get the last 7 days record u...

Read More

Jan-31-2022

How to Downgrade PHP 8.2 to 8.1 in Ubuntu
How to Downgrade PHP 8.2 to 8....

Hey there, I recently found myself in a situation where I needed to downgrade my PHP version from 8.2 to 8.1 on my Ubunt...

Read More

Nov-01-2023

How To Get Last 15 Days Records In MySQL
How To Get Last 15 Days Record...

In this tutorial, we will see how to get the last 15 days records in MySQL PHP.  In PHP, you can use INTERVAL...

Read More

Feb-09-2022