π Introduction
Tailwind CSS is not just a utility-first framework β it's a developer-friendly toolkit that helps you build modern, responsive UIs fast.
While the basic classes are well-known, there are some clever tricks and techniques in Tailwind that can level up your workflow.
In this post, Iβll share 7 Tailwind CSS tricks that I use regularly β from responsive layouts to dark mode and hover animations.
β‘ 1. Responsive Utilities Are Just One Prefix Away
Tailwind uses mobile-first breakpoints that make responsive design super intuitive.
<h1 class="text-lg md:text-xl lg:text-2xl">
Responsive Heading
</h1>
β No custom media queries. Just use sm:, md:, lg:, xl:, and 2xl:.
π― 2. Group Hover for Advanced Effects
Want to change child styles on parent hover? Use group.
<div class="group hover:bg-gray-100 p-4">
<h2 class="text-lg group-hover:text-blue-500">Title</h2>
</div>
π 3. Dark Mode Made Simple
Activate dark mode in tailwind.config.js:
darkMode: 'class',
Then use:
<div class="bg-white text-black dark:bg-black dark:text-white">
Light/Dark Mode Ready
</div>
π₯ 4. @apply for Custom Components
Use Tailwind inside your CSS to create reusable classes:
/* styles.css */
.btn-primary {
@apply px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700;
}
<button class="btn-primary">Click Me</button>
β Cleaner HTML and DRY code for common components.
π 5. Line Clamping for Truncation
Need to limit text to 2 or 3 lines? Use the line-clamp plugin:
npm install @tailwindcss/line-clamp
// tailwind.config.js
plugins: [require('@tailwindcss/line-clamp')],
<p class="line-clamp-2">
This is a very long paragraph that will be cut after two lines...
</p>
π 6. Aspect Ratio for Images and Videos
Install the plugin:
npm install @tailwindcss/aspect-ratio
plugins: [require('@tailwindcss/aspect-ratio')],
<div class="aspect-w-16 aspect-h-9">
<iframe src="..." allowfullscreen></iframe>
</div>
β Keeps media perfectly scaled across all devices.
π¨ 7. Custom Colors & Fonts in tailwind.config.js
Define your own theme:
extend: {
colors: {
primary: '#FF6B6B',
},
fontFamily: {
gilroy: ['Gilroy', 'sans-serif'],
},
}
Then use:
<h1 class="text-primary font-gilroy">Hello Brand</h1>
π Final Thoughts
Tailwind CSS makes styling not just faster β but smarter. With tricks like these, you can build responsive, clean, and scalable UIs without writing a single line of custom CSS.
These small tips have saved me hours and made my code much easier to maintain.
π¬ Whatβs Your Favorite Tailwind Trick?
Let me know in the comments or tag me on Twitter/X β and follow me for more frontend blogs!
Top comments (0)