How To Setup React and Tailwind CSS With Vite in A Project
How To Setup React and Tailwind CSS With Vite in A Project
Forum Donate
And Tailwind CSS and React are a great combo to use if you're
Alt +building
A a frontend project.
https://www.freecodecamp.org/news/how-to-install-tailwindcss-in-react/ 1/14
8/4/24, 14:52 How to Setup React and Tailwind CSS with Vite in a Project
In this article, you will learn how to setup your coding Forum
environmentDonate
with Vite, install React and Tailwind CSS with their latest versions,
Learn to code — free 3,000-hour curriculum
and start building your projects right away.
If you don't have these tools installed, you can do so by clicking the
links for each one above.
After setting up Node.js for your VSCode, you can now use Node.js
to install Vite for your project using the terminal.
https://www.freecodecamp.org/news/how-to-install-tailwindcss-in-react/ 2/14
8/4/24, 14:52 How to Setup React and Tailwind CSS with Vite in a Project
cd food-app
This command will navigate to your project folder. You should have
this:
https://www.freecodecamp.org/news/how-to-install-tailwindcss-in-react/ 3/14
8/4/24, 14:52 How to Setup React and Tailwind CSS with Vite in a Project
Forum Donate
npm install -D tailwindcss postcss autoprefixer
https://www.freecodecamp.org/news/how-to-install-tailwindcss-in-react/ 4/14
8/4/24, 14:52 How to Setup React and Tailwind CSS with Vite in a Project
Forum Donate
https://www.freecodecamp.org/news/how-to-install-tailwindcss-in-react/ 5/14
8/4/24, 14:52 How to Setup React and Tailwind CSS with Vite in a Project
Forum Donate
This command generates tailwind.config.cjs
Learn to code — free 3,000-hour curriculum
and postcss.config.cjs configuration files, also known as config
files. They help you interact with your project and customize
everything.
"./index.html",
https://www.freecodecamp.org/news/how-to-install-tailwindcss-in-react/ 6/14
8/4/24, 14:52 How to Setup React and Tailwind CSS with Vite in a Project
Forum Donate
"./src/**/*.{js,ts,jsx,tsx}",
https://www.freecodecamp.org/news/how-to-install-tailwindcss-in-react/ 7/14
8/4/24, 14:52 How to Setup React and Tailwind CSS with Vite in a Project
Forum Donate
@tailwind base;
@tailwind components;
Learn to code — free 3,000-hour curriculum
@tailwind utilities;
@tailwind base;
@tailwind components;
@tailwind utilities;
The three directives added to the index.css file - @tailwind base, @tailwind
components and @tailwind utilities
Your index.css file contains some default styling. You can clear all
that and paste the three lines of directives above.
The message you get after running your Vite server that provides localhost link,
network, and help.
https://www.freecodecamp.org/news/how-to-install-tailwindcss-in-react/ 8/14
8/4/24, 14:52 How to Setup React and Tailwind CSS with Vite in a Project
Forum Donate
Hold the ctrl key and click on the link at Local – here it's
Learn to code — free 3,000-hour curriculum
http://127.0.0.1:5174. It will open a new tab in your browser if you
do that.
Our styles are broken because we cleared the default CSS in the
index.css file to input our directives.
https://www.freecodecamp.org/news/how-to-install-tailwindcss-in-react/ 9/14
8/4/24, 14:52 How to Setup React and Tailwind CSS with Vite in a Project
Forum Donate
Clear the return element starting from line 9, and replace it with the
text below to test your Tailwind to know if it is working. Input this:
https://www.freecodecamp.org/news/how-to-install-tailwindcss-in-react/ 10/14
8/4/24, 14:52 How to Setup React and Tailwind CSS with Vite in a Project
Forum Donate
You can learn more about Tailwind classnames here. Your browser
should update automatically.
https://www.freecodecamp.org/news/how-to-install-tailwindcss-in-react/ 11/14
8/4/24, 14:52 How to Setup React and Tailwind CSS with Vite in a Project
You can now start building your React projects and style them withDonate
Forum
Tailwind CSS.
Learn to code — free 3,000-hour curriculum
Conclusion
You have now created a React and Tailwind CSS app using Vite, a
frontend build tool. You have learned what Vite is and how to create
a Vite app with a React template, as well as how to install Tailwind
and other dependencies.
Thanks for reading this article. If you enjoyed it, consider sharing it
to help other developers.
Happy Learning.
Segun Ajibola
Software developer and technical writer
If you read this far, thank the author to show them you care.
Say Thanks
https://www.freecodecamp.org/news/how-to-install-tailwindcss-in-react/ 12/14
8/4/24, 14:52 How to Setup React and Tailwind CSS with Vite in a Project
Forum Donate
Our mission: to help people learn to code for free. We accomplish this by creating thousands of
videos, articles, and interactive coding lessons - all freely available to the public.
Donations to freeCodeCamp go toward our education initiatives, and help pay for servers,
services, and staff.
Trending Guides
https://www.freecodecamp.org/news/how-to-install-tailwindcss-in-react/ 13/14
8/4/24, 14:52 How to Setup React and Tailwind CSS with Vite in a Project
Mobile App
Forum Donate
Our Charity
About Alumni Network Open Source Shop Support Sponsors Academic Honesty
https://www.freecodecamp.org/news/how-to-install-tailwindcss-in-react/ 14/14