Card basics
A card is a flexible box with optional image, body, title and text.
In this page:
Syntax
<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
<!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
- Forgetting card-body
- Fixed pixel widths
- 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: