Technology

Adding Tailwind CSS to React

Though this is a simple first, the tailwind documentation seems to be a roundabout way of doing this. so thought I can share what may be a simple step to start using tailwind, especially for beginners. No frills to waste our time adding Tailwind CSS to React!

1 – Create the React Project

Most of us prefer typescript as we want to ensure type-checking alongside coding. The below command creates a react project in the folder ‘my-tailwind-app’

npx create-react-app my-tailwind-app --template typescript
(or)
npm create vite@latest for using vite and follow the steps

change the directory by using the ‘cd my-tailwind-app’ folder

2 – Tailwind CSS

Install tailwind using the command prompt in the same my-tailwind-app folder.

npm install -D tailwindcss postcss autoprefixer

Run the command to initialize tailwind inside the project
npx tailwindcss init -p

3 – Add support for js, and ts in the tailwind config

Open VSCode or any other editor and add content to use “./src/**/*.{js,jsx, ts,tsx}” in tailwind.config.js as below

  • add the below directives to index.css
    @tailwind base;
    @tailwind components;
    @tailwind utilities;
Tailwind CSS to React

Run the project

Run using ‘npm start’ for the project created with create-react-app or ‘npm run dev’ for the project created with vite and view the results on the browser.

Published by CoderSource.net | A growing community of coders..

admin

Recent Posts

Streamlining Patient Transit and Asset Management: The Ultimate Hospital Facility Management Application

Hospital Facility Management: In the rapidly evolving healthcare sector, effective facility management is crucial for…

4 days ago

Custom Software Development in 2024: A Journey Through Innovation and Looking Ahead to 2025

Custom Software Development: As we bid farewell to 2024, we at PM Square Soft Services…

3 weeks ago

Harnessing ARM Architecture: Running Zephyr RTOS on Raspberry Pi 4 with Xen

Running Zephyr RTOS on Raspberry Pi 4: The Raspberry Pi 4 is an ARM-based device…

2 months ago

Exploring Model-View Architecture in Qt using C++

The Model-View architecture in Qt is a design pattern that separates the data (model) from…

2 months ago

ASP.NET Project Structure – A Comprehensive guide to setup project in C#

ASP.NET Project Structure Using a structured approach in any project is important because it helps…

3 months ago

AI vs Generative AI: Which Technology is Right for Your Mobile App?

In the ever-evolving world of technology, distinguishing between Artificial Intelligence AI vs Generative AI Gen AI is essential…

4 months ago