TExcelTAD
Home › Bootstrap › BS5 Cards

Bootstrap 5 Cards

A card is a flexible bordered box for a self-contained piece of content: a product, a blog post, a user profile, a pricing plan. Cards replaced Bootstrap 3's panels, wells and thumbnails. They have no fixed width — they fill their parent, so you size them with the grid or width utilities.

Card anatomy

Class Part
.card The outer box
.card-header / .card-footer Optional top / bottom strips
.card-body Padded content area
.card-title / .card-subtitle Headings inside the body
.card-text Paragraph text
.card-link Links side by side
.card-img-top / .card-img-bottom Image flush with the top/bottom edge
.card-img-overlay Puts the body on top of a .card-img
html · try it yourself
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
  <div class="card" style="max-width: 20rem;">
    <div class="card-header">Featured</div>
    <div class="card-body">
      <h5 class="card-title">Weekend hiking trip</h5>
      <h6 class="card-subtitle mb-2 text-body-secondary">Saturday, 8:00</h6>
      <p class="card-text">A 12 km loop through the forest with a picnic at the lake.</p>
      <a href="#" class="card-link">Join</a>
      <a href="#" class="card-link">Share</a>
    </div>
    <div class="card-footer text-body-secondary small">14 people going</div>
  </div>
</body>
</html>

Images in cards

.card-img-top puts an image at the top with matching rounded corners. With .card-img-overlay the text sits on top of the picture instead.

html · try it yourself
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
  <div class="row g-3">
    <div class="col-6">
      <div class="card h-100">
        <img class="card-img-top" alt="" height="90"
             src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 100' preserveAspectRatio='none'%3E%3Crect width='300' height='100' fill='%2320c997'/%3E%3Ccircle cx='240' cy='30' r='18' fill='%23ffc107'/%3E%3Cpath d='M0 100 L90 40 L160 100 Z' fill='%23198754'/%3E%3C/svg%3E">
        <div class="card-body">
          <h6 class="card-title">Mountains</h6>
          <p class="card-text small">Image on top.</p>
        </div>
      </div>
    </div>
    <div class="col-6">
      <div class="card text-white h-100" style="background: linear-gradient(160deg, #6f42c1, #d63384);">
        <div class="card-img-overlay d-flex flex-column justify-content-end">
          <h6 class="card-title">Night city 🌃</h6>
          <p class="card-text small">Text over the background.</p>
        </div>
      </div>
    </div>
  </div>
</body>
</html>

Colours and borders

Card colours come from the regular utilities: .text-bg-{color} for solid cards, .border-{color} for outlined ones.

html · try it yourself
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
  <div class="row g-2">
    <div class="col-4"><div class="card text-bg-primary"><div class="card-body p-2">Primary</div></div></div>
    <div class="col-4"><div class="card text-bg-success"><div class="card-body p-2">Success</div></div></div>
    <div class="col-4"><div class="card text-bg-dark"><div class="card-body p-2">Dark</div></div></div>
    <div class="col-6">
      <div class="card border-danger">
        <div class="card-header bg-transparent border-danger text-danger">Outlined</div>
        <div class="card-body p-2 text-danger">Border colour only</div>
      </div>
    </div>
    <div class="col-6">
      <div class="card shadow">
        <div class="card-body p-2">With <code>.shadow</code></div>
      </div>
    </div>
  </div>
</body>
</html>

Card grids

To lay out many cards, use the grid with row-cols-*: row-cols-1 row-cols-sm-2 row-cols-lg-3 means one card per row on phones, two from sm and three from lg. Add .h-100 to each card so the cards in a row are equally tall.

html · try it yourself
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
  <div class="row row-cols-1 row-cols-sm-2 row-cols-lg-3 g-3">
    <div class="col"><div class="card h-100"><div class="card-body"><h6>☕ Basic</h6><p class="small mb-0">Short text.</p></div></div></div>
    <div class="col"><div class="card h-100"><div class="card-body"><h6>🚀 Pro</h6><p class="small mb-0">A longer description that makes this card taller than its neighbours.</p></div></div></div>
    <div class="col"><div class="card h-100"><div class="card-body"><h6>🏢 Team</h6><p class="small mb-0">Medium text here.</p></div></div></div>
  </div>
</body>
</html>

Note: In the narrow preview frame you'll probably see two cards per row. Resize your browser window to see the one- and three-column versions.

Horizontal cards and stretched links

Combine the grid inside a card to place an image beside the text. And adding .stretched-link to a link makes the whole card clickable (the card must be positioned, which .card already is).

Tip: .card-group glues cards together with no gutters and equal heights; on phones they stack. Use it when cards belong together, e.g. a three-step process.

Test yourself

Which class holds the padded content of a card?

  1. .card-content
  2. .card-body
  3. .card-inner
  4. .card-text

How do you make all cards in a grid row the same height?

  1. Add .card-equal
  2. Add .h-100 to each card
  3. Use .card-deck
  4. Set height on the row

Which class puts card text on top of an image?

  1. .card-img-overlay
  2. .card-img-top
  3. .card-overlay-text
  4. .position-absolute