,

Installing Tailwind CSS in Vite React JS: A Step-by-Step Guide

Posted by

How to Install Tailwind CSS in to Vite React JS

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:

  1. First, create a new Vite React JS project by running the following command in your terminal:
  2. npx create-vite@latest my-react-app --template react

  3. Next, navigate into the project folder by running:
  4. cd my-react-app

  5. Install Tailwind CSS and its dependencies by running the following command:
  6. npm install -D tailwindcss@latest postcss@latest autoprefixer@latest

  7. Create a Tailwind CSS configuration file by running:
  8. npx tailwindcss init -p

  9. Modify the tailwind.config.js file to include any customizations you require.
  10. Create a postcss.config.js file with the following content:
  11. 
      module.exports = {
        plugins: [
          require('tailwindcss'),
          require('autoprefixer'),
        ]
      }
      
  12. Import Tailwind CSS in your main CSS file. Create a new CSS file, for example src/index.css, and include the following:
  13. 
      @import 'tailwindcss/base';
      @import 'tailwindcss/components';
      @import 'tailwindcss/utilities';
      
  14. Import the CSS file in your React components. For example, in your App.js file:
  15. 
      import './index.css';
      
  16. You can now start your development server by running:
  17. 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.

0 0 votes
Article Rating

Leave a Reply

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@Error404xxx
1 day ago

did not work

@Tally_RSA
1 day ago

Thanks bro, I always mess up my installion by forgeting postcss and autoprefefixer👍🏾

2
0
Would love your thoughts, please comment.x
()
x