Tutorial · 9 min read

How to Use Tailwind CSS in React: Complete Guide 2026

Tailwind CSS and React are the most popular pairing for building modern web UIs. In this guide, you will learn how to install Tailwind CSS in a React project (including Next.js), configure it correctly, and start using free copy-paste Tailwind components to build your UI faster.

Prerequisites

Before you begin, make sure you have the following installed:

  • Node.js v18 or later (check with: node --version)
  • npm v9+ or pnpm v8+ or yarn v4+
  • A code editor (VS Code is recommended — install the Tailwind CSS IntelliSense extension)

Step 1: Create Your React or Next.js Project

You can use Tailwind CSS with any React setup, but Next.js is the most popular choice in 2026. Choose one:

Create a Next.js project

bash
npx create-next-app@latest my-app
# Choose: TypeScript ✓ | ESLint ✓ | Tailwind CSS ✓ | App Router ✓
cd my-app

If you select "Tailwind CSS: Yes" during the Next.js setup, Tailwind is automatically configured. You can skip to Step 5.

Create a Vite + React project

bash
npm create vite@latest my-app -- --template react-ts
cd my-app
npm install

Step 2: Install Tailwind CSS

Install Tailwind CSS v4 and its PostCSS plugin:

bash
npm install tailwindcss @tailwindcss/postcss postcss

Tailwind CSS v4 (released January 2025) uses a new CSS-first configuration approach. The tailwind.config.ts file is now optional — all configuration can be done directly in CSS.

Step 3: Configure PostCSS

Create or update postcss.config.mjs in your project root:

postcss.config.mjs
const config = {
  plugins: {
    "@tailwindcss/postcss": {},
  },
};

export default config;

Step 4: Add Tailwind to Your CSS

Open your global CSS file (app/globals.css in Next.js or src/index.css in Vite) and add the Tailwind import:

globals.css
@import "tailwindcss";

/* Add custom styles below */

Tailwind v4 Note: In Tailwind v4, you use @import "tailwindcss" instead of the old @tailwind base; @tailwind components; @tailwind utilities; directives. The old syntax still works but the new import is recommended.

Step 5: Write Your First Tailwind React Component

Now you can use Tailwind utility classes in your React components. Here is a simple card component:

tsx
// components/Card.tsx
export function Card({ title, description }: { title: string; description: string }) {
  return (
    <div className="rounded-2xl border border-gray-200 p-6 hover:shadow-md transition-shadow">
      <h2 className="text-xl font-semibold text-gray-900 mb-2">{title}</h2>
      <p className="text-gray-600 text-sm leading-relaxed">{description}</p>
    </div>
  );
}

Notice we use className instead of class in JSX. This is a React requirement — all Tailwind components in JSX format use className.

Step 6: Use Free Pre-Built Tailwind CSS Components

Building every component from scratch is time-consuming. Tailwindready provides free copy-paste Tailwind CSS components in JSX format, perfectly suited for React and Next.js projects.

To use a component from Tailwindready:

  1. 1

    Browse to a component category — for example, Hero Sections or Card Components.

  2. 2

    Click the "JSX" toggle above the component preview to get the React-compatible version.

  3. 3

    Click "Copy" and paste the JSX code directly into your React component file.

  4. 4

    Customize the colors, text, and layout to match your project.

Tips & Best Practices for Tailwind in React

Install the Tailwind IntelliSense VS Code Extension

The official Tailwind CSS IntelliSense extension provides autocomplete, hover previews, and linting for class names. It dramatically speeds up development.

Use clsx or tailwind-merge for Conditional Classes

When applying classes conditionally, use clsx(condition && 'class-name') or tailwind-merge() to avoid class conflicts. Avoid string concatenation with template literals for complex conditions.

Define Custom Colors in tailwind.config

Add your brand colors to the theme.extend.colors section of tailwind.config.ts. This lets you use them as bg-brand-500 or text-brand-700 throughout your app.

Create Component Variants with cva

The cva (class-variance-authority) library is popular in the React/Tailwind ecosystem for creating components with multiple variants (like buttons in 'primary' and 'secondary' styles).

Purge is Automatic in Production

Tailwind v4 automatically removes unused CSS in production builds. You don't need to configure the 'content' array manually in most setups — it scans all files by default.

Frequently Asked Questions

Can I use Tailwind CSS with React class components?

Yes. Tailwind CSS is just CSS utility classes. It works with functional components, class components, and any React rendering pattern.

Does Tailwind CSS work with CSS Modules in React?

Yes, but they serve different purposes. Tailwind is utility-first and works directly in JSX. CSS Modules scope custom CSS. You can use both in the same project.

How do I use Tailwind CSS with Styled Components or Emotion?

Tailwind and CSS-in-JS libraries like Styled Components can coexist in the same project, but using both adds complexity. For new projects, choose one approach.

Is Tailwind CSS suitable for large React applications?

Yes. Many large-scale applications — including Vercel, GitHub, and Shopify — use Tailwind CSS. Its utility-first approach scales well because there is no global CSS to manage.

What is the best way to handle dark mode in Tailwind React?

Tailwind supports dark mode natively with the 'dark:' prefix. Configure 'darkMode: class' in tailwind.config and toggle the 'dark' class on the <html> element using React state or next-themes.

Now add free Tailwind CSS components to your React app

Your project is configured. Speed up development with copy-paste Tailwind CSS UI components.

Continue Reading