How To Make Beautiful Pages Using Tailwind CSS and Laravel
انتشار: مرداد 09، 1402
بروزرسانی: 27 خرداد 1404

How To Make Beautiful Pages Using Tailwind CSS and Laravel


Every Laravel website can use some style, and Tailwind CSS is the easiest way to give your site some flair. This utility-first CSS framework offers predefined classes to style your HTML elements. Instead of writing endless CSS code, you can build custom web pages quickly and then easily maintain and scale your stylesheets.

Tailwind is part of the TALL stack, along with Alpine.js and Livewire. The Laravel community built this full-stack development solution to help developers of all skill levels quickly prototype web applications. These solutions are easy to use without deep knowledge of front-end or back-end technologies.

This hands-on article explores how to use Tailwind CSS to spice up your Laravel project, then deploy it using MyKinsta.

Enhance Your Laravel Project Using Tailwind

To get started, create a basic Laravel page, then use Tailwind CSS to style it with minimal effort.

Prerequisites

To follow along with the tutorial, you need:

To see the final project, check out the complete project code.

Laravel Project and Set Up Tailwind

To create a new Laravel project using Composer:

  1. Open the terminal to the directory where you want the project to live and run:
composer create-project laravel/laravel my-project
  1. Go to the my-project\xa0directory to install the required packages:
cd my-project
  1. Install the packages to work with Tailwind:
npm install -D tailwindcss postcss autoprefixer
  1. \xa0Run the following command to set up Tailwind’s configuration files:
npx tailwindcss init -p

This action places two files at your project’s root: tailwind.config.js\xa0and postcss.config.js.

Configure Your Template Paths

  1. Next, configure your template paths in the tailwind.config.js\xa0file. Laravel looks for CSS files in the public directory by default. The template path tells Laravel where to find the application’s CSS files.
  1. Replace the code inside the tailwind.config.js\xa0file with this:
/** @type {import(\'tailwindcss\').Config} */
module.exports = {
content: [
"./resources/**/*.blade.php",
"./resources/**/*.js",
"./resources/**/*.vue",
],
theme: {
extend: {},
},
plugins: [],
}