Tailwind CSS in React

Last Updated : 18 Jun 2026

Tailwind CSS is a utility-based CSS framework used to design user interfaces in React applications. It provides predefined utility classes that help developers apply styling directly inside React components without writing large custom CSS files.

Using Tailwind CSS, you can create layouts, forms, buttons, cards, and responsive pages using utility classes.

Tailwind CSS also supports customization and responsive design. During the production build process, unused CSS classes are removed automatically, which helps reduce the final CSS file size.

Setting Up Tailwind CSS with React

1. Create your project

Start by creating a new React project with Create React App v5.0+ if you don't have one already set up. Type in terminal:

2. Install Tailwind CSS

Install tailwindcss via npm, and then run the init command to generate your tailwind.config.js file.

3. Create a CSS File

In your project, create a CSS file (e.g., styles.css) where you'll import and apply Tailwind CSS classes. Import the Tailwind CSS stylesheet at the beginning of your CSS file.

4. Import the CSS File

Import the CSS file you just created in your React application's entry point (e.g., index.js or App.js):

5. Add the Tailwind directives to your CSS

Add the @tailwind directives for each of Tailwind's layers to your ./src/index.css file.

6. Start your build process

Run your build process with npm run start.

7. Start using Tailwind in your project

Start using Tailwind's utility classes to style your content.

Using Tailwind CSS Classes in React

1. Applying Classes

In your JSX components, apply Tailwind CSS classes to HTML elements as needed. For example:

We've applied various Tailwind CSS classes to style the div, h1, and button elements in the above example.

2. Conditional Classes

You can also conditionally apply classes based on component props or state. For example: