DEV Community

Saravanan s
Saravanan s

Posted on

Using Tailwind CSS with React.js

what is tailwind
Tailwind CSS is a utility-first CSS framework that enables developers to quickly build modern and responsive user interfaces. When combined with React.js, a popular JavaScript library for building user interfaces, the two technologies synergize to streamline the development process. In this article, we'll explore how to integrate Tailwind CSS seamlessly into a React.js project.

Step 1: Create a React App

If you haven't already set up a React app, use the following commands to create one:

npx create-react-app my-tailwind-app
cd my-tailwind-app

Enter fullscreen mode Exit fullscreen mode

Step 2: Install Tailwind CSS

Next, install Tailwind CSS and its dependencies usingnpm:

npm install tailwindcss postcss autoprefixer

Enter fullscreen mode Exit fullscreen mode

Step 3: Configure Tailwind CSS

Create a tailwind.config.jsfile in the root of your project and configure it:

Import Tailwind CSS in your styles

Open the src/index.css file and import Tailwind CSS

src/index.css 
@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';

Enter fullscreen mode Exit fullscreen mode

Run your React App

Finally, start your React app to see the integration in action:

npm start
Enter fullscreen mode Exit fullscreen mode

Visit http://localhost:5173in your browser, and you should see your React app with Tailwind CSS styles applied.

Top comments (0)