This guide will walk you through the process of setting up Tailwind CSS in a React project from scratch.
Prerequisites Before you begin, make sure you have the following installed:
Node.js npm or yarn (Choose one)
If you haven't already created a React project, you can do so by running the following command:
npx create-react-app my-tailwind-project
Replace my-tailwind-project with your preferred project name.
Navigate to your project directory and install Tailwind CSS along with its dependencies:
cd my-tailwind-project npm install tailwindcss postcss autoprefixer --save
Create a tailwind.config.js file in the root of your project to customize Tailwind CSS according to your needs:
npx tailwindcss init This will generate a default tailwind.config.js file which you can modify as required.
Create a postcss.config.js file in the root of your project to configure PostCSS:
module.exports = { plugins: [ require('tailwindcss'), require('autoprefixer'), ] }
In your src/index.css file, import Tailwind CSS styles:
@import 'tailwindcss/base'; @import 'tailwindcss/components'; @import 'tailwindcss/utilities';
Run your React project:
npm start
Your React project should now be running with Tailwind CSS integrated. You can start building awesome UI components with Tailwind CSS utility classes!
Tailwind CSS Documentation , React Documentation
Javascript, HTML, CSS...