Master Code
On The Go

Learn. Practice. Build.

CSS Guide

What Is Tailwind CSS?

Tailwind CSS is a utility-first CSS framework that lets you style elements directly in your HTML. Here's what makes it popular and how it changes the way you write CSS.

Quick answer: Tailwind CSS gives you hundreds of small utility classes (flex, p-4, bg-blue-500) that you compose directly in your HTML. Instead of writing custom CSS, you combine utilities to build any design.

💡 Why Tailwind Matters

⚖️ Traditional CSS vs Tailwind

Same card, two approaches:

Traditional CSS:

/* style.css */
.card {
    background: white;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    max-width: 400px;
}
.card h2 {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 8px;
}
<!-- HTML -->
<div class="card">
    <h2>Hello</h2>
</div>

Tailwind CSS:

<div class="bg-white rounded-xl p-6 shadow-lg max-w-md">
    <h2 class="text-xl font-bold mb-2">Hello</h2>
</div>

No separate CSS file. Everything is visible at the point of use.

🧩 Common Tailwind Classes

/* Layout */
flex, grid, block, hidden

/* Spacing */
p-4          padding: 1rem
px-6         padding left+right: 1.5rem
mt-8         margin top: 2rem
gap-4        gap between flex/grid items

/* Sizing */
w-full       width: 100%
max-w-md     max-width: 28rem
h-screen     height: 100vh

/* Typography */
text-xl      font-size: 1.25rem
font-bold    font-weight: 700
text-slate-600

/* Colors */
bg-blue-500
text-white
border-slate-200

/* Borders & shadows */
rounded-lg
border
shadow-md

/* Responsive */
md:flex      flex on screens >= 768px
lg:grid-cols-3
1

Try It Instantly with CDN

For learning, add one script tag to any HTML file:

<script src="https://cdn.tailwindcss.com"></script>

Now every Tailwind class works. This is great for prototyping.

💡 Don't use the CDN in production. It ships the entire framework (~3MB). For real projects, install Tailwind via npm so it only includes the classes you use.

2

Install for a Real Project

In a Node.js project, install Tailwind properly:

npm install -D tailwindcss
npx tailwindcss init

Then add the directives to your CSS file:

@tailwind base;
@tailwind components;
@tailwind utilities;

Finally, run the build to generate your CSS:

npx tailwindcss -i ./input.css -o ./output.css --watch
3

Use It in Frameworks

Tailwind has first-class support for every modern framework:

  • Next.js: npx create-next-app@latest — Tailwind is offered during setup
  • Vite + React: npm install -D tailwindcss postcss autoprefixer
  • Astro: npx astro add tailwind

🚫 Common Beginner Mistakes

❓ Frequently Asked Questions

What is Tailwind CSS?

A utility-first CSS framework. You compose small classes in your HTML instead of writing custom CSS rules.

Is Tailwind better than custom CSS?

Tailwind is faster to build with and enforces consistency. Custom CSS is better for highly unique or animation-heavy designs. Most modern projects use Tailwind.

Do I need to know CSS first?

Yes. Tailwind uses CSS properties under the hood. Learn flexbox, grid, and box model before Tailwind.

Does Tailwind make HTML messy?

It can look verbose at first. But it removes the need to invent class names and jump between files. Most developers find it faster once they adapt.

Is Tailwind free?

Yes. Open source and free for personal and commercial use.

🎯 What's Next?

← All How-To Guides