Step-by-Step Guide to Installing React and Setting Up TailwindCSS Effectively

Ahmadreza Shamimi
2 min readNov 13, 2023

--

Set Up Node.js and npm:

  • Ensure Node.js and npm (Node Package Manager) are installed on your system. You can download them from Node.js website.

Create React App:

  • Use the create-react-app tool to set up a new React project. Run this command in your terminal:
npx create-react-app app
  • This will create a new directory named app with a basic React project setup.

Navigate to the Project Directory:

Change your current working directory to the newly created app directory:

cd app

Install Tailwind CSS: Install Tailwind CSS via npm:

npm install tailwindcss postcss autoprefixer
  • devDependencies on package.json
  "devDependencies": {
"autoprefixer": "^10.4.16",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"postcss": "^8.4.31",
"prettier": "^2.7.1",
"tailwindcss": "^3.3.5"
}

Generate Tailwind Configuration File:

npx tailwindcss init -p                     

Configure Tailwind to Remove Unused Styles in Production:

/** @type {import('tailwindcss').Config} */
module.exports = {
content: ["../src/**/*.{js,jsx,ts,tsx}"],//Add this line
theme: {
extend: {},
},
plugins: [],
};

Include Tailwind in your CSS:

Open the ./src/index.css file and add the following Tailwind directives to the top of your file:

@tailwind base;
@tailwind components;
@tailwind utilities;

Run Your React App:

npm start

Your React application should now be running with Tailwind CSS integrated.

With Tailwind CSS installed, you can start using its utility classes to style your React components. Remember to check the Tailwind CSS documentation for more detailed information and advanced configurations.

--

--

Ahmadreza Shamimi
Ahmadreza Shamimi

Written by Ahmadreza Shamimi

I'm Ahmadreza Shamimi with an experienced with over 10 years of experience coding with web and mobile platforms.

No responses yet