Building a Card Component: UI Design with Tailwind CSS
Learn how to build a professional, responsive card component from scratch using Tailwind CSS. Master layout, shadows, borders, and spacing utilities.

Previously in this course, we explored Managing Z-Index and Positioning to handle complex layout overlaps. Now, we're taking those foundational skills to build a functional, reusable card component—a staple of any modern marketing site.
When you think of UI design and cards, don't just see them as "boxes." Think of them as containers that establish visual hierarchy. They group related information, provide clear boundaries, and keep your layout organized.
Structuring the Card HTML
A well-structured card is semantic. We typically use an <article> or <div> as our main wrapper. Inside, we need a clear hierarchy: a visual area (like an image or icon), a content area (heading and body text), and a footer (often for buttons or links).
Here is the fundamental structure:
HTMLstyle="color:#808080"><style="color:#4EC9B0">article class="bg-white rounded-lg shadow-md overflow-hidden"> style="color:#808080"><style="color:#4EC9B0">div class="h-48 bg-gray-200">style="color:#808080"></style="color:#4EC9B0">div> <!-- Placeholder for image --> style="color:#808080"><style="color:#4EC9B0">div class="p-6"> style="color:#808080"><style="color:#4EC9B0">h3 class="text-xl font-bold text-gray-900">Card Titlestyle="color:#808080"></style="color:#4EC9B0">h3> style="color:#808080"><style="color:#4EC9B0">p class="mt-2 text-gray-600">This is where your card description goes.style="color:#808080"></style="color:#4EC9B0">p> style="color:#808080"><style="color:#4EC9B0">div class="mt-4"> style="color:#808080"><style="color:#4EC9B0">button class="bg-blue-600 text-white px-4 py-2 rounded">Actionstyle="color:#808080"></style="color:#4EC9B0">button> style="color:#808080"></style="color:#4EC9B0">div> style="color:#808080"></style="color:#4EC9B0">div> style="color:#808080"></style="color:#4EC9B0">article>
Applying Layout, Shadow, and Border Utilities
To make this component feel "polished," we rely on three key pillars:
- Layout: We use
overflow-hiddenon the parent to ensure rounded corners aren't clipped by child images. We useflexorgridinside the card if we need complex side-by-side arrangements. - Shadows: Shadows create depth. A subtle
shadow-mdorshadow-lghelps the card "lift" off the page, signaling to the user that it’s an interactive element. - Borders: Sometimes a shadow isn't enough. Using
border border-gray-100adds a crisp edge, especially useful if your card is placed on a light gray background.
| Utility Type | Class Example | Purpose |
|---|---|---|
| Shadow | shadow-md | Adds elevation/depth |
| Border | border border-gray-200 | Defines boundaries |
| Rounding | rounded-xl | Softens the aesthetic |
| Overflow | overflow-hidden | Clips child elements to radius |
Making the Card Responsive
In Advanced Responsive Patterns, we learned that components should adapt to their container. For a card, responsiveness usually means adjusting the padding or the layout of the internal content.
For example, on mobile, you might want a simpler, vertical layout. On larger screens, you might want to switch to a horizontal layout (where the image sits to the left of the text).
HTMLstyle="color:#808080"><style="color:#4EC9B0">article class="bg-white rounded-xl shadow-lg border border-gray-100 md:flex"> style="color:#808080"><style="color:#4EC9B0">div class="md:w-1/3 bg-gray-200">style="color:#808080"></style="color:#4EC9B0">div> <!-- Image section --> style="color:#808080"><style="color:#4EC9B0">div class="p-6 md:w-2/3"> style="color:#808080"><style="color:#4EC9B0">h3 class="text-xl font-bold">Responsive Titlestyle="color:#808080"></style="color:#4EC9B0">h3> style="color:#808080"><style="color:#4EC9B0">p class="mt-2">This card shifts layout at the md breakpoint.style="color:#808080"></style="color:#4EC9B0">p> style="color:#808080"></style="color:#4EC9B0">div> style="color:#808080"></style="color:#4EC9B0">article>
Hands-on Exercise
- Create a
card.htmlfile. - Build a card that contains an image placeholder, a heading, a paragraph, and a button.
- Apply
rounded-2xlto the container andshadow-xlfor a "premium" feel. - Add a
hover:shadow-2xlclass to the container to make it interactive when the user hovers over it.
Common Pitfalls
- Forgetting
overflow-hidden: If you add an image inside a rounded container and don't useoverflow-hidden, the image corners will spill over the rounded edges of the card. - Inconsistent Padding: Always use the same spacing scale (e.g.,
p-6) for your internal content. Mixingp-4andp-8inside the same card design leads to a messy, unprofessional look. - Over-nesting: Try to keep your HTML structure flat. Deeply nested divs make it harder to manage the layout with flexbox or grid.
FAQ
Q: Should I use div or article for cards?
A: If the card represents an independent, self-contained piece of content (like a blog post preview or a feature highlight), use <article>. It's better for SEO and accessibility.
Q: How do I handle images that don't fit the aspect ratio?
A: Use the object-cover utility on your <img> tag combined with a fixed height on the container to ensure the image fills the space without stretching.
Q: When should I switch from a standard card to a component?
A: If you find yourself copying and pasting the same 10-15 classes across your project, it’s time to move toward a component-based approach using @apply or a framework-specific component, as discussed in Component Library Design.
Recap
We've moved from basic utility application to crafting a cohesive card component. By combining layout, depth (shadows), and responsive modifiers, you've created a UI element that is both functional and visually balanced. Use these building blocks to ensure your marketing site remains consistent and professional.
Up next: Building a Testimonial Section where we will group these cards into a repeating, balanced layout.
Work with me

Next.js Full-Stack Web App Development
A fast, SEO-ready full-stack web app built with Next.js 16 — from idea to deployed product, by an engineer who ships to production.

Next.js Website & Landing Page Development
A blazing-fast, SEO-optimized website or landing page in Next.js — the kind that loads instantly and ranks. Design-to-code, done right.


