Clean β’ Professional
Tailwind CSS is a utility-first CSS framework that allows developers to build responsive, modern, and highly customizable user interfaces quickly. Unlike traditional CSS, Tailwind focuses on small, reusable utility classes, enabling rapid development without writing custom styles from scratch.
Integrating Tailwind with React makes your apps fast, maintainable, and scalable, while keeping your styling close to your components.
_20251024_060545.png&w=3840&q=75)
className in React components.If using Create React App:
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
tailwind.config.js β for customizing Tailwindβs themepostcss.config.js β for processing Tailwind stylesAdd paths to your React components in tailwind.config.js:
module.exports = {
content: [
"./src/**/*.{js,jsx,ts,tsx}",
],
theme: {
extend: {},
},
plugins: [],
};
In src/index.css (or App.css):
@tailwind base;
@tailwind components;
@tailwind utilities;
Tailwind works directly with the className attribute.
Example:
export default function App() {
return (
<div className="flex flex-col items-center justify-center min-h-screen bg-gray-100">
<h1 className="text-4xl font-bold text-blue-600 mb-4">Welcome to Tailwind CSS</h1>
<button className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
Click Me
</button>
</div>
);
}
flex flex-col items-center justify-center β Flexbox layout utilitiesmin-h-screen β Minimum height of full screenbg-gray-100 β Light gray backgroundhover:bg-blue-700 β Hover effect on buttonResponsive Design Example:
<div className="p-4 sm:p-6 md:p-8 lg:p-10 bg-white shadow-md rounded">
<h2 className="text-lg sm:text-xl md:text-2xl font-semibold">Responsive Card</h2>
<p className="text-gray-700">This card adjusts its padding and font size based on screen size.</p>
</div>
React state can dynamically change classes:
import { useState } from "react";
export default function ToggleButton() {
const [active, setActive] = useState(false);
return (
<buttonclassName={`py-2 px-4 rounded font-bold ${
active ? "bg-green-500 text-white" : "bg-gray-300 text-black"
}`}
onClick={() => setActive(!active)}
>
{active ? "Active" : "Inactive"}
</button>
);
}
| Feature | Benefit |
|---|---|
| Utility-First | Quickly build UI without writing custom CSS |
| Responsive | Mobile-first design built-in |
| Customizable | Extend colors, spacing, typography in config |
| Fast Prototyping | Rapid development with ready-to-use classes |
| Scoped Styling | Works directly in JSX, no global CSS conflicts |