← Back to Bootstrap Course | Chapter 7: Components — Cards & Alerts | Lesson 1 of 7

Card basics

A card is a flexible box with optional image, body, title and text.

In this page:

  1. Card basics
Syntax
markup
<div class="card">
  <img src="image.jpg" class="card-img-top" alt="...">
  <div class="card-body">
    <h5 class="card-title">Title</h5>
    <p class="card-text">Text</p>
    <a href="#" class="btn btn-primary">Button</a>
  </div>
</div>

Card basics

Start with .card and add .card-img-top, then .card-body containing .card-title, .card-text and buttons. Cards have no fixed width by default, so control it with grid columns or width utilities. They combine well with list groups.

Note: Use grid columns around cards to control their width responsively.

Example: Card basics

markup
<!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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
<div class="container">
  <div class="card" style="max-width: 18rem">
    <div class="card-body">
      <h5 class="card-title">Card title</h5>
      <p class="card-text">Some quick example text for the card body.</p>
      <a href="#" class="btn btn-primary">Go somewhere</a>
    </div>
  </div>
</div>
</body>
</html>
Live Example
Related Topics
Common Mistakes
  1. Forgetting card-body
  2. Fixed pixel widths
  3. Heading tags chosen only for size
Chapter Summary
  • .card is the container
  • card-body holds content
  • card-title and card-text
  • Width comes from the layout
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.