Tailwind CSS is a utility-first CSS framework that makes building modern, responsive UIs fast and easy. Instead of writing custom CSS, Tailwind provides low-level utility classes that you can compose directly in your HTML.
tailwind.config.js.You can install Tailwind CSS via PostCSS or using frameworks like Next.js, Vite, or CRA.
Hereβs a basic setup using npm:
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
This will generate:
tailwind.config.jspostcss.config.jsUpdate your tailwind.config.js file to set the content paths:
module.exports = {
content: [
"./index.html",
"./src/**/*.{js,ts,jsx,tsx}",
],
theme: {
extend: {},
},
plugins: [],
}
In your main CSS file (e.g., index.css or globals.css), add:
@tailwind base;
@tailwind components;
@tailwind utilities;
<button class="bg-blue-500 hover:bg-blue-600 text-white font-bold py-2 px-4 rounded">
Click Me
</button>
This single line styles your button with a blue background, hover effect, padding, and rounded corners β no custom CSS needed!
Tailwind uses mobile-first breakpoints:
<div class="text-sm md:text-lg lg:text-xl">
Responsive Text
</div>
text-sm: default for small devicesmd:text-lg: on medium screens and uplg:text-xl: on large screens and upYou can customize colors, fonts, spacing, etc., inside tailwind.config.js:
module.exports = {
theme: {
extend: {
colors: {
brand: "#1DA1F2",
},
},
},
}
Use it like:
<div class="bg-brand text-white p-4">Branded Box</div>