Setup Tailwind CSS in React
In this post we will see how to install tailwind.css in react
Installation
- Install tailwind with the below command
 
yarn add tailwindcss postcss-cli autoprefixer -D
- Create a PostCSS configuration file in your root directory manually or you can use the command:
 
touch postcss.config.js
- paste the below code in the config file
 
const tailwindcss = require('tailwindcss');
module.exports = {
    plugins: [
        tailwindcss('./tailwind.js'),
        require('autoprefixer')
    ],
};
- Create 2 .css files in 
src/assets/name them astailwind.cssandmain.css - Add below code to 
tailwind.cssfile 
@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";
- Go to 
package.jsonand change thescriptsas below 
"scripts": {
    "start": "npm run watch:css && react-scripts start",
    "build": "npm run build:css && react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "build:css": "postcss src/assets/tailwind.css -o src/assets/main.css", 
    "watch:css": "postcss src/assets/tailwind.css -o src/assets/main.css"
  },
- Go to 
index.jsand import themain.cssand deleteindex.cssimport 
import './assets/main.css'
That's it. whenever you run the build or start comand the tailwind css will be compiled and added to main.css file. Now you can use tailwind.css.