Tailwind CSS is a utility-first CSS framework that allows developers to build modern and responsive user interfaces directly within their HTML or JSX.
Unlike traditional CSS frameworks that provide pre-built components, Tailwind provides low-level utility classes that can be combined to create custom designs.
Tailwind CSS has become one of the most popular CSS frameworks because it offers:
For a Next.js project:
npm install tailwindcss @tailwindcss/postcss
Create your CSS file:
@import "tailwindcss";
<button class="bg-blue-500 text-white px-4 py-2 rounded">
Click Me
</button>
bg-blue-500 → Blue backgroundtext-white → White textpx-4 → Horizontal paddingpy-2 → Vertical paddingrounded → Rounded cornersTailwind provides hundreds of color utilities.
<div class="bg-red-500 text-white p-4">
Red Box
</div>
Some common colors:
bg-blue-500
bg-green-500
bg-red-500
bg-yellow-500
bg-purple-500
<p class="text-xs">Extra Small</p>
<p class="text-sm">Small</p>
<p class="text-base">Base</p>
<p class="text-lg">Large</p>
<p class="text-xl">Extra Large</p>
<p class="font-light">Light</p>
<p class="font-normal">Normal</p>
<p class="font-medium">Medium</p>
<p class="font-bold">Bold</p>
<p class="text-left">Left</p>
<p class="text-center">Center</p>
<p class="text-right">Right</p>
Spacing is controlled using padding and margin.
<div class="p-4">
Padding
</div>
p-1
p-2
p-4
p-6
p-8
<div class="m-4">
Margin
</div>
Examples:
mt-4
mb-4
ml-4
mr-4
mx-auto
<div class="w-64 h-32 bg-blue-500"></div>
Common values:
w-full
w-screen
h-screen
<div class="border border-gray-300">
Border
</div>
Rounded corners:
rounded
rounded-md
rounded-lg
rounded-xl
rounded-full
<div class="shadow-md">
Card
</div>
Available shadows:
shadow-sm
shadow
shadow-md
shadow-lg
shadow-xl
Flexbox makes layout creation easy.
<div class="flex">
<div>One</div>
<div>Two</div>
</div>
justify-start
justify-center
justify-end
justify-between
justify-around
Example:
<div class="flex justify-between">
<div>Logo</div>
<div>Menu</div>
</div>
items-start
items-center
items-end
Example:
<div class="flex items-center">
Content
</div>
<div class="grid grid-cols-2 gap-4">
<div>Item 1</div>
<div>Item 2</div>
</div>
<div class="grid grid-cols-3 gap-4">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
Tailwind uses breakpoint prefixes.
<div class="text-sm md:text-lg lg:text-2xl">
Responsive Text
</div>
Breakpoints:
sm: 640px
md: 768px
lg: 1024px
xl: 1280px
2xl: 1536px
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3">
Content
</div>
<button class="bg-blue-500 hover:bg-blue-700">
Hover Me
</button>
<input
class="border focus:outline-none focus:ring-2 focus:ring-blue-500"
/>
<button
class="transition duration-300 hover:scale-105"
>
Hover
</button>
hover:scale-105
hover:rotate-6
hover:-translate-y-1
relative
absolute
fixed
sticky
Example:
<div class="relative">
<div class="absolute top-0 right-0">
Badge
</div>
</div>
Tailwind supports dark mode.
<div class="bg-white dark:bg-black">
Content
</div>
Text example:
<p class="text-black dark:text-white">
Hello
</p>
<div class="rounded-xl shadow-md p-6 bg-white">
<h2 class="text-xl font-bold">
Tailwind Card
</h2>
<p class="text-gray-600">
Simple card component.
</p>
</div>
<button
class="px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition"
>
Button
</button>
<nav class="flex justify-between items-center p-4">
<h1>Logo</h1>
<div class="flex gap-4">
<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Contact</a>
</div>
</nav>
Tailwind CSS is a powerful utility-first framework that helps developers create beautiful, responsive, and modern user interfaces quickly. By mastering utility classes such as spacing, colors, typography, flexbox, grid, and responsive design, you can build professional websites without writing large amounts of custom CSS.
Learning Tailwind CSS is one of the best investments for modern frontend development and works perfectly with React, Next.js, and other JavaScript frameworks.