agyanadda@gmail.com

Tailwind Cards

Building Components 1 min read Updated Dec 1, 2026 Topic 20 of 27

A card is a box with a background, padding, rounded corners and a shadow:

<div class="bg-white rounded-2xl shadow-sm p-6">

Typical parts

  • Image: w-full h-48 object-cover (and rounded-t-2xl)
  • Badge: inline-block text-xs font-semibold bg-emerald-100 text-emerald-700 px-2 py-1 rounded-full
  • Title: text-lg font-semibold
  • Text: text-slate-600 text-sm
  • Footer / button: pushed to the bottom with mt-auto inside flex flex-col

Card grid

grid sm:grid-cols-2 lg:grid-cols-3 gap-6 — grid items stretch, so all cards in a row are the same height automatically.

Make the whole card clickable

Wrap it in an <a> with block group, and use group-hover: for effects.

Example

Example — Course card grid HTML
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>

<div class="bg-slate-100 p-6">
  <div class="grid sm:grid-cols-2 lg:grid-cols-3 gap-6">
    <a href="#" class="group flex flex-col bg-white rounded-2xl shadow-sm hover:shadow-xl transition overflow-hidden">
      <img src="https://picsum.photos/id/0/600/300" class="w-full h-40 object-cover group-hover:scale-105 transition duration-500" alt="Laptop">
      <div class="flex flex-col flex-1 p-5">
        <span class="self-start text-xs font-semibold bg-emerald-100 text-emerald-700 px-2 py-1 rounded-full">Free</span>
        <h3 class="mt-3 text-lg font-semibold group-hover:text-indigo-600">HTML Tutorial</h3>
        <p class="text-sm text-slate-600 mt-1">Learn the structure of every web page.</p>
        <div class="mt-auto pt-4 flex justify-between text-sm text-slate-500"><span>33 lessons</span><span>★ 4.8</span></div>
      </div>
    </a>
    <a href="#" class="group flex flex-col bg-white rounded-2xl shadow-sm hover:shadow-xl transition overflow-hidden">
      <img src="https://picsum.photos/id/180/600/300" class="w-full h-40 object-cover group-hover:scale-105 transition duration-500" alt="Desk">
      <div class="flex flex-col flex-1 p-5">
        <span class="self-start text-xs font-semibold bg-sky-100 text-sky-700 px-2 py-1 rounded-full">New</span>
        <h3 class="mt-3 text-lg font-semibold group-hover:text-indigo-600">Tailwind CSS Tutorial</h3>
        <p class="text-sm text-slate-600 mt-1">Design modern, responsive pages fast with utility classes.</p>
        <div class="mt-auto pt-4 flex justify-between text-sm text-slate-500"><span>27 lessons</span><span>★ 4.9</span></div>
      </div>
    </a>
    <div class="flex flex-col items-center text-center bg-white rounded-2xl shadow-sm p-6">
      <img src="https://picsum.photos/id/64/120/120" class="size-20 rounded-full ring-4 ring-indigo-100" alt="Mentor">
      <h3 class="mt-3 font-semibold">Ravi Kumar</h3>
      <p class="text-sm text-slate-500">Frontend Mentor</p>
      <button class="mt-4 w-full bg-indigo-600 hover:bg-indigo-700 text-white rounded-lg py-2">Book a session</button>
    </div>
  </div>
</div>

Test Yourself With Exercises

Exercise 1 Multiple Choice

Which class makes an image fill its box without stretching?

Exercise 2 True / False

Items in a CSS grid row stretch to the same height by default.

Exercise 3 Fill in the Blank

Inside a flex-col card, mt-___ pushes the footer to the bottom.

Frequently Asked Questions

Create a Blade component (resources/views/components/card.blade.php) with the classes and a {{ $slot }}, then use <x-card> everywhere.