Versatile card component with image, badge, and hover effects using Tailwind CSS
Quick Answer
A Tailwind CSS card uses rounded-2xl shadow overflow-hidden and the group + group-hover: utilities to trigger smooth image scale and shadow transitions from the parent wrapper.
1<div class="group bg-white rounded-2xl shadow-sm hover:shadow-lg transition-shadow duration-300 overflow-hidden border border-gray-100">
2 <div class="relative overflow-hidden">
3 <img src="https://images.unsplash.com/photo-1555066931-4365d14bab8c?w=400&h=240&fit=crop" alt="Card image" class="w-full h-48 object-cover group-hover:scale-105 transition-transform duration-300" />
4 <span class="absolute top-3 left-3 text-xs font-semibold bg-indigo-600 text-white px-2.5 py-1 rounded-full">Tutorial</span>
5 </div>
6 <div class="p-5">
7 <div class="flex items-center gap-2 text-xs text-gray-400 mb-3">
8 <span>March 2025</span><span>·</span><span>5 min read</span>
9 </div>
10 <h3 class="text-base font-semibold text-gray-900 mb-2 line-clamp-2 group-hover:text-indigo-600 transition-colors">Getting Started with Tailwind CSS in 2025</h3>
11 <p class="text-sm text-gray-500 line-clamp-2 mb-4">A complete guide to setting up Tailwind CSS in your next project and leveraging utility-first design.</p>
12 <a href="#" class="inline-flex items-center text-sm font-medium text-indigo-600 hover:text-indigo-800 transition-colors gap-1">Read more
13 <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 8l4 4m0 0l-4 4m4-4H3"/></svg>
14 </a>
15 </div>
16</div>Card components are among the most reused UI elements in any design system. This Tailwind CSS card includes an image with an overlay badge, a content section with title and description, and a smooth hover shadow transition — all achievable without writing a single line of custom CSS.
Wrap the card in an <a> tag and move the group class to it. This ensures the hover effects still propagate while the whole surface is a single accessible link.
Add dark: variant classes: dark:bg-gray-800 dark:border-gray-700 dark:text-white dark:text-gray-400 alongside every light-mode colour class.
This free html code snippet for card component is production-ready and copy-paste friendly. Whether you are building a web app, API, or frontend interface, this beginner-level example will help you implement card component quickly and correctly.
All snippets in the Snippetly library follow html best practices and are tested for real-world use. You can adapt this code to work with React, Vue, Node.js, or any project that uses html.
Organise your team's code snippets with Snippetly. Share knowledge and boost productivity across your organisation.