How to Install Tailwind CSS in to Vite React JS
If you are looking to install Tailwind CSS in a Vite React JS project, follow these steps:
- First, create a new Vite React JS project by running the following command in your terminal:
- Next, navigate into the project folder by running:
- Install Tailwind CSS and its dependencies by running the following command:
- Create a Tailwind CSS configuration file by running:
- Modify the
tailwind.config.js
file to include any customizations you require. - Create a
postcss.config.js
file with the following content: - Import Tailwind CSS in your main CSS file. Create a new CSS file, for example
src/index.css
, and include the following: - Import the CSS file in your React components. For example, in your
App.js
file: - You can now start your development server by running:
npx create-vite@latest my-react-app --template react
cd my-react-app
npm install -D tailwindcss@latest postcss@latest autoprefixer@latest
npx tailwindcss init -p
module.exports = {
plugins: [
require('tailwindcss'),
require('autoprefixer'),
]
}
@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';
import './index.css';
npm run dev
Congratulations! You have successfully installed Tailwind CSS in your Vite React JS project. You can now start styling your components using Tailwind CSS utilities.
did not work
Thanks bro, I always mess up my installion by forgeting postcss and autoprefefixer👍🏾