Web development has changed drastically over the years. Gone are the days when developers had to manually write hundreds of lines of CSS for even simple websites. Today, frameworks like Tailwind CSS empower developers to build modern, responsive, and customizable UIs faster than ever.
This guide is designed to give you a complete understanding of Tailwind CSS β from the basics to advanced customization. It also includes real-world examples, code snippets (with copy button support in MDX), and best practices. By the end, youβll be ready to confidently use Tailwind CSS in your projects.
Tailwind CSS is a utility-first CSS framework. Unlike traditional frameworks (like Bootstrap), Tailwind doesnβt come with pre-styled UI components. Instead, it provides low-level utility classes that you can combine to create your own custom designs.
For example, instead of using a predefined button component, you write:
<button class="bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700">
Click Me
</button>
This gives you complete control over your design.
Here are some reasons why developers love Tailwind CSS:
sm:
, md:
, lg:
.tailwind.config.js
.Installing Tailwind is easy. Letβs set it up in a Next.js project:
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
tailwind.config.js
:/** @type {import('tailwindcss').Config} */
export default {
content: [
"./pages/**/*.{js,ts,jsx,tsx,mdx}",
"./components/**/*.{js,ts,jsx,tsx,mdx}",
],
theme: {
extend: {},
},
plugins: [],
}
globals.css
:@tailwind base;
@tailwind components;
@tailwind utilities;
Now youβre ready π.
Traditional CSS:
.button {
background-color: #1d4ed8;
color: white;
padding: 0.5rem 1rem;
border-radius: 0.5rem;
}
Tailwind equivalent:
<button class="bg-blue-700 text-white px-4 py-2 rounded-lg">
Click Me
</button>
Instead of jumping between HTML and CSS, everything stays inline.
Responsive design is effortless with Tailwind.
Example:
<p class="text-base sm:text-lg md:text-xl lg:text-2xl">
Responsive text size π± π» π₯οΈ
</p>
sm:
β small devicesmd:
β tabletslg:
β laptopsxl:
β large screensDark mode is built into Tailwind.
tailwind.config.js
:export default {
darkMode: 'class', // or 'media'
theme: {
extend: {},
},
}
dark:
prefix:<div class="bg-white text-gray-800 dark:bg-gray-900 dark:text-gray-100">
This supports dark mode π
</div>
Toggle by adding class="dark"
to <html>
.
For blog posts, Tailwind provides @tailwindcss/typography
.
Install:
npm install @tailwindcss/typography
Add to config:
plugins: [require('@tailwindcss/typography')],
Wrap your MDX content:
<article className="prose prose-lg prose-blue dark:prose-invert">
{children}
</article>
Now Markdown content looks gorgeous out of the box.
Tailwind is fully customizable.
Example tailwind.config.js
:
theme: {
extend: {
colors: {
brand: {
DEFAULT: '#1E40AF',
light: '#60A5FA',
dark: '#1E3A8A',
},
},
fontFamily: {
sans: ['Inter', 'sans-serif'],
},
},
},
Usage:
<h1 class="text-brand">Custom Color Heading</h1>
Letβs build a Card Component:
<div class="max-w-sm mx-auto bg-white dark:bg-gray-800 rounded-2xl shadow-md overflow-hidden hover:shadow-lg transition">
<img src="https://via.placeholder.com/400x200" alt="Card Image" class="w-full" />
<div class="p-4">
<h2 class="text-xl font-bold text-gray-800 dark:text-white">Tailwind Card</h2>
<p class="text-gray-600 dark:text-gray-300 mt-2">This is a responsive card component built with Tailwind CSS.</p>
<button class="mt-4 bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700">
Learn More
</button>
</div>
</div>
In MDX blogs, you can add a copy-to-clipboard button:
"use client"
import { useState } from "react"
import { Copy } from "lucide-react"
export default function CodeBlock({ children }: { children: string }) {
const [copied, setCopied] = useState(false)
const copyToClipboard = async () => {
await navigator.clipboard.writeText(children)
setCopied(true)
setTimeout(() => setCopied(false), 2000)
}
return (
<div className="relative my-4 rounded-lg bg-gray-900 text-gray-100 overflow-hidden">
<button
onClick={copyToClipboard}
className="absolute top-2 right-2 flex items-center gap-1 rounded-md bg-gray-800 px-2 py-1 text-xs text-gray-300 hover:bg-gray-700"
>
<Copy size={14} />
{copied ? "Copied!" : "Copy"}
</button>
<pre className="overflow-x-auto p-4 text-sm">
<code>{children}</code>
</pre>
</div>
)
}
Now every code block has a βCopyβ button β
π If you want full control, Tailwind is the winner.
prose
for Markdown β Beautiful typography for blogs.Tailwind CSS is more than just a framework β itβs a design philosophy. By embracing utility-first styling, you gain speed, flexibility, and consistency in your projects.
From responsive design to dark mode, from prose typography to copy buttons in MDX blogs, Tailwind has everything you need to build modern, scalable UIs.
If you havenβt tried Tailwind yet, now is the perfect time.
π₯ Happy coding, and may your designs always be pixel-perfect!