Discover 10 powerful Tailwind CSS tips and techniques that will supercharge your development workflow. From custom utilities to responsive patterns, level up your styling game.
After years of using Tailwind CSS in production, I've collected some tips that dramatically improved my workflow. Here are my top 10 recommendations.
Instead of hardcoding colors, use CSS variables for easy theming:
/* globals.css */
@layer base {
:root {
--primary: 221 83% 53%;
--primary-foreground: 210 40% 98%;
}
}
// tailwind.config.ts
theme: {
extend: {
colors: {
primary: "hsl(var(--primary))",
"primary-foreground": "hsl(var(--primary-foreground))",
},
},
},
Create interactive components without JavaScript:
<!-- Hover parent, style child -->
<div class="group">
<h3 class="group-hover:text-blue-500">Title</h3>
<p class="group-hover:opacity-100 opacity-0">Description</p>
</div>
<!-- Sibling state styling -->
<input type="checkbox" class="peer" />
<label class="peer-checked:text-green-500">Checked!</label>
Don't fight Tailwind for unique values:
<div class="w-[327px] h-[calc(100vh-80px)] bg-[#1a1a2e]">
<span class="text-[13px] leading-[1.7]">Custom sizing</span>
</div>
Responsive design based on parent, not viewport:
<div class="@container">
<div class="@lg:flex @lg:gap-4">
<div class="@lg:w-1/2">Responsive to container</div>
<div class="@lg:w-1/2">Not viewport</div>
</div>
</div>
size UtilityShorthand for width and height:
<!-- Before -->
<div class="w-10 h-10"></div>
<!-- After -->
<div class="size-10"></div>
Multi-line text truncation:
<!-- Single line -->
<p class="truncate">Very long text...</p>
<!-- Multiple lines -->
<p class="line-clamp-3">
This text will be truncated after three lines with an ellipsis...
</p>
Consistent spacing between children:
<div class="space-y-4">
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
</div>
<!-- With dividers -->
<div class="divide-y divide-gray-200">
<div class="py-4">Section 1</div>
<div class="py-4">Section 2</div>
</div>
Beautiful gradient text effects:
<h1 class="bg-gradient-to-r from-purple-500 via-pink-500 to-red-500
bg-clip-text text-transparent">
Gradient Heading
</h1>
Better focus states for keyboard navigation:
<!-- Only shows focus ring on keyboard navigation -->
<button class="focus-visible:ring-2 focus-visible:ring-blue-500
focus-visible:outline-none">
Click me
</button>
Create unique animations:
// tailwind.config.ts
theme: {
extend: {
animation: {
"fade-in": "fadeIn 0.5s ease-out",
"slide-up": "slideUp 0.3s ease-out",
},
keyframes: {
fadeIn: {
"0%": { opacity: "0" },
"100%": { opacity: "1" },
},
slideUp: {
"0%": { transform: "translateY(20px)", opacity: "0" },
"100%": { transform: "translateY(0)", opacity: "1" },
},
},
},
},
<div class="animate-fade-in">Fades in</div>
<div class="animate-slide-up">Slides up</div>
Here's a reusable card pattern:
<div class="rounded-lg border bg-card p-6 shadow-sm
transition-shadow hover:shadow-md">
<h3 class="text-lg font-semibold">Card Title</h3>
<p class="mt-2 text-muted-foreground">
Card description with helpful information.
</p>
<div class="mt-4 flex gap-2">
<button class="rounded bg-primary px-4 py-2 text-sm
text-primary-foreground hover:bg-primary/90">
Action
</button>
</div>
</div>
Tailwind CSS is incredibly powerful once you learn its patterns. These tips should help you write cleaner, more maintainable styles while keeping your productivity high.
What's your favorite Tailwind tip? Share it in the comments!
Get the latest articles, tutorials, and updates delivered straight to your inbox. No spam, unsubscribe at any time.