How to Install Tailwind CSS with Create React App?
Last Updated :
20 Jan, 2025
We will see how to set up Tailwind CSS in a React project using the Create React App. Tailwind CSS is a utility-first CSS framework that allows for rapid development of custom user interfaces. When combined with Create React App, it offers a flexible approach to build modern React applications.
Prerequisites
Before proceeding, ensure you have the following installed:
- Node.js: Download and install from Node.js official website.
- Create React App: A simple way to create a new React application.
Steps to Set Up Tailwind CSS with Create React App
Follow these steps to integrate Tailwind CSS into your React project:
Step 1: Create a New React App
If you haven't already installed Create React App, you can do so by running the following command:
npx create-react-app my-tailwind-app
Note: Replace my-tailwind-app with the name of your project.
Step 2: Install Tailwind CSS
Navigate into your project directory:
cd my-tailwind-app
Now, install Tailwind CSS and its dependencies:
npm install tailwindcss postcss autoprefixer
Step 3: Configure Tailwind CSS
Create a tailwind.config.js file in the root directory of your project:
npx tailwindcss init
This command generates a tailwind.config.js file where you can customize Tailwind CSS according to your needs.
Step 4: Create PostCSS Configuration
Create a postcss.config.js file in the root directory and add the following content:
module.exports = {
plugins: [
require('tailwindcss'),
require('autoprefixer'),
],
}
This configures PostCSS to use Tailwind CSS and autoprefixer.
Step 5: Include Tailwind CSS in Your Stylesheets
Open the src/index.css file and import Tailwind CSS:
/* ./src/index.css */
@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";
Step 6: Configure your template paths
Add the paths to all of your template files in your tailwind.config.js file
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./src/**/*.{js,jsx,ts,tsx}",
],
theme: {
extend: {},
},
plugins: [],
}
Step 7: Start Your React App
Now, start your React app:
npm start
Your app should now be up and running with Tailwind CSS integrated. You can start using Tailwind CSS utility classes in your React components.
Example: Using Tailwind CSS in a React Component
Let's create a simple React component to demonstrate how to use Tailwind CSS classes:
React
// ./src/App.js
import React from 'react';
function App() {
return (
<div className="flex justify-center items-center h-screen bg-blue-500">
<h1 className="text-4xl text-white font-bold">Hello, Tailwind CSS!</h1>
</div>
);
}
export default App;
Output:
Similar Reads
How to Create Tailwind CSS Profile Card in React?
TailwindCSS can be integrated with React to create highly customizable and responsive profile cards by using utility-first classes for styling. This approach allows you to design visually appealing cards with gradients, rounded corners, and interactive animations, all while ensuring seamless respons
3 min read
How to Create a Sidebar in NextJS & Tailwind CSS?
In web development, sidebars are commonly used to organize navigation elements and provide quick access to different sections of a website. A sidebar is a vertical menu or panel that is typically positioned on the left or right side of the main content area. Prerequisites:Next.jsTailwindJavaScriptSt
5 min read
How to setup Tailwind 3 in React with CRA 5 ?
In this article, we will see how to set up Tailwind 3 in React with CRA 5, but before that, we need some basic ideas about these technologies. React JS: A free and open-source front-end JavaScript library for building user interfaces or UI components. It is maintained by Facebook.TailwindCSS: A high
3 min read
How to use Ant Design with Tailwind CSS in a React Project ?
The integration of Ant Design and Tailwind CSS in a React project presents challenges due to their differing styling conventions. Ant Design offers a feature-rich component library with its own class names, while Tailwind CSS provides a utility-first framework for custom designs. Combining both libr
2 min read
Create Dropdowns UI using React and Tailwind CSS
Dropdown UI components are often used in web applications for forms, navigation, or user preferences, allow users to select from a list of options by clicking a button, which will display a drop-down menu, in this article we will create a dropdown element using React for functionality and Tailwind C
3 min read
Create Dropdowns UI with Next.JS and Tailwind CSS
Dropdowns are an essential component of web applications used for navigation, filtering data or selecting items from a list. In this article, weâll explore how to create a clean and responsive dropdown UI using Next.js and Tailwind CSS. Tailwind's utility-first CSS framework allows us to easily styl
3 min read
Create FAQs using React and Tailwind CSS
A Frequently Asked Questions section is a common feature found on websites and applications that helps users find answers to common queries in an organized manner. A well-designed FAQ can improve user experience reduce support requests and provide users with quick and easy access to helpful informat
5 min read
Create Footers Using React And Tailwind CSS
We will learn how to create a responsive footer using React and Tailwind CSS with a modern design. The footer will feature a green background with white text providing a clean and professional look. We will create three sections: Contacts social media and Services to display important information an
3 min read
Create Flyout Menus using React and Tailwind CSS
Flyout menus are a type of navigational menu that can be displayed when the user hovers over or clicks on an item allowing for a clean and organized display of additional options without crowding the main interface. In this article, we will create a responsive flyout menu using React and Tailwind CS
4 min read
Create Header using React and Tailwind CSS
In modern web development building responsive and customizable user interfaces is crucial. One of the essential elements of any web application is the header which typically contains navigation links branding or other important controls. we will create a responsive header section using React and Tai
4 min read