Add Tailwind CSS to Vite + React
📁 Make sure you’re inside your project folder:
cd E:/study/code it/web/frontend/react/E-commerce/test-app
🔧 Step 1: Install Tailwind and dependencies
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
This will create:
tailwind.config.js
postcss.config.js
Step 2: Configure tailwind.config.js
Open tailwind.config.js and set the content option to scan your files:
/** @type {import('tailwindcss').Config} */
export default {
content: [
"./index.html",
"./src/**/*.{js,ts,jsx,tsx}",
],
theme: {
extend: {},
},
plugins: [],
🎨 Step 3: Add Tailwind directives to CSS
Open src/index.css and replace everything with:
@tailwind base;
@tailwind components;
@tailwind utilities;
📥 Step 4: Import the CSS in your app
Make sure src/main.jsx includes:
import './index.css';
Usually it's already there in the default template.
🧪 Step 5: Test Tailwind
Edit src/App.jsx like this:
function App() {
return (
<div className="min-h-screen flex items-center justify-center bg-gradient-to-r from-
purple-500 to-pink-500 text-white">
<h1 className="text-4xl font-bold">🚀 Tailwind + React + Vite!</h1>
</div>
);
export default App;