In this tutorial, we will learn how to set up Tailwind CSS with Vite in under 60 seconds. Tailwind CSS is a popular utility-first CSS framework, while Vite is a modern build tool that helps with fast and efficient development. By combining Tailwind CSS with Vite, we can create a seamless development experience for building responsive and intuitive web applications.
To get started, make sure you have Node.js installed on your machine. If not, you can download and install it from the official Node.js website. Once Node.js is installed, open your terminal and create a new React project by running the following command:
npx create-react-app my-tailwind-project
Next, navigate into your project directory by running the following command:
cd my-tailwind-project
Now, let’s install Tailwind CSS and its dependencies by running the following command:
npm install -D tailwindcss@latest postcss@latest autoprefixer@latest
After installing Tailwind CSS, you need to generate a Tailwind configuration file by running the following command:
npx tailwindcss init
Next, create a tailwind.css
file in your src
directory and add the following Tailwind CSS imports:
@tailwind base;
@tailwind components;
@tailwind utilities;
Now, let’s set up Vite to work with Tailwind CSS. Create a vite.config.js
file in the root of your project and add the following configuration:
import { defineConfig } from 'vite';
import reactRefresh from '@vitejs/plugin-react-refresh';
import WindiCSS from 'vite-plugin-windicss';
export default defineConfig({
plugins: [reactRefresh(), WindiCSS()],
});
Finally, you can import the tailwind.css
file in your index.css
file to apply Tailwind CSS styles to your React components:
@import './src/tailwind.css';
That’s it! You have successfully set up Tailwind CSS with Vite in your React project. Now you can start building amazing web applications with responsive and intuitive designs using Tailwind CSS. Happy coding!
Bro sara setup ho vya hae ract with tailwind but tailwind property apply nhi ho rhi hae UI me
What is the error showing in the index.css file
Not working i am doing same steps but tailwind is not working
Thanku bro it's helpful 😌
Nhi ho rha💔