![]() |
In this article, we will see how to install Tailwind CSS with React. Tailwind CSS is a utility-first CSS framework that allows you to rapidly build custom user interfaces. Combining it with Create React App offers a powerful combination for developing React applications. PrerequisitesSteps to Set up Tailwind CSS with Create React AppStep 1: Create a New React AppIf you haven’t already installed Create React App, you can do so by running the following command: npx create-react-app my-tailwind-app
Note: Replace my-tailwind-app with the name of your project. Step 2: Install Tailwind CSSNavigate into your project directory: cd my-tailwind-app
Now, install Tailwind CSS and its dependencies: npm install tailwindcss postcss autoprefixer
Step 3: Configure Tailwind CSSCreate a tailwind.config.js file in the root directory of your project: npx tailwindcss init
This command generates a tailwind.config.js file where you can customize Tailwind CSS according to your needs. Step 4: Create PostCSS ConfigurationCreate a postcss.config.js file in the root directory and add the following content: module.exports = { This configures PostCSS to use Tailwind CSS and autoprefixer. Step 5: Include Tailwind CSS in Your StylesheetsOpen the src/index.css file and import Tailwind CSS: /* ./src/index.css */ Step 6: Configure your template pathsAdd the paths to all of your template files in your tailwind.config.js file /** @type {import('tailwindcss').Config} */ Step 7: Start Your React AppNow, start your React app: npm start
Your app should now be up and running with Tailwind CSS integrated. You can start using Tailwind CSS utility classes in your React components. Output: |
Reffered: https://www.geeksforgeeks.org
ReactJS |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 15 |