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

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 weeks 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…

1 month 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…

2 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…

3 months ago

Efficient Git Repository Management: Mirroring Code to Client Repositories

Mirroring Git Repository: In the world of software development, managing code repositories efficiently is crucial,…

7 months ago

The Future of Healthcare Software: Some Types to Watch

As the healthcare IT market is projected to reach $907.18 billion by 2031, growing at…

8 months ago