DEV Community

Daniel Musembi
Daniel Musembi

Posted on

HOW TO CONFIGURE TAILWIND CSS IN A REACT PROJECT

Let's start by defining what tailwind CSS is;

A utility-first CSS framework packed with classes like flex, pt-4, text-center, and rotate-90 that can be composed to build any design, directly in your markup.

To configure tailwind CSS in a react project, first, we need to visit the tailwind CSS website https://tailwindcss.com/ and click the get started button.

For the option of installation click Framework Guides.

Image description

then click on Create React App

Image description.

After creating your react project, you need to go to step two which is installing tailwind CSS using VS Code terminal.

Image description

Make sure you cd into your react project before you start installing tailwind CSS.

Once you have cd into your project folder, copy past the command
npm, install -D tailwindcss postcss autoprefixer on the terminal and click enter to start installing.

Image description

After you're through with installing, copy the other copy-paste command npx tailwindcss init -p on the terminal which will create
tow files on your react project.

Image description

Image description

The next step is to configure your template paths, first, we need to clear everything on the tailwind.config.js file.

Image description

After clearing the content inside the tailwind.config.js file, copy and paste content from https://tailwindcss.com/docs/guides/create-react-app tailwind.config.js to your tailwind. config .js file.

Image description

Image description

The next step is to add tailwind directives to your CSS, so here we are going to copy-paste content on step four into our index.css file.

Image description

Click on the project's index.css file, paste the content, and save the file.

Image description

Let's finalize this by testing if our tailwind CSS is working, first, we go into the App.js file and remove the header.

Image description

After Removing the Header, replace the App class with a class from tailwind CSS like bg-red-500.

Image description

Image description

So now we can test if the changes are affected by running npm start on the terminal.

Image description

Image description

And from the browser, we can see we have successfully installed and configured tailwind CSS in our application.

In conclusion let's see the importance of using tailwind CSS

Tailwind CSS basically makes it quicker to write and maintain the code of your application. By using this utility-first framework, you don't have to write custom CSS to style your application. Instead, you can use utility classes to control the padding, margin, color, font, shadow, and more of your application.

Top comments (0)