Card groups and decks help you show multiple cards together in a neat, organized way. They make your webpage look clean and balanced.
Card groups and decks in Bootsrap
<div class="card-group"> <div class="card">...</div> <div class="card">...</div> <div class="card">...</div> </div> <div class="d-flex justify-content-between"> <div class="card">...</div> <div class="card">...</div> <div class="card">...</div> </div>
.card-group makes cards share the same height and appear connected.
Use d-flex and spacing utilities instead of .card-deck in Bootstrap 5 to space cards evenly with margin between them.
card-group makes both cards the same height and places them side by side without space between.<div class="card-group"> <div class="card"> <img src="image1.jpg" class="card-img-top" alt="..."> <div class="card-body"> <h5 class="card-title">Card 1</h5> <p class="card-text">Some text.</p> </div> </div> <div class="card"> <img src="image2.jpg" class="card-img-top" alt="..."> <div class="card-body"> <h5 class="card-title">Card 2</h5> <p class="card-text">Some text.</p> </div> </div> </div>
<div class="d-flex justify-content-between"> <div class="card" style="width: 18rem;"> <div class="card-body"> <h5 class="card-title">Card A</h5> <p class="card-text">Text A.</p> </div> </div> <div class="card" style="width: 18rem;"> <div class="card-body"> <h5 class="card-title">Card B</h5> <p class="card-text">Text B.</p> </div> </div> </div>
This example shows two sections: a card group where cards share the same height and appear connected, and a flex container used instead of card deck where cards have space between them for a balanced look.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Bootstrap Card Group and Deck Example</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <main class="container my-4"> <h2>Card Group Example</h2> <div class="card-group"> <div class="card"> <img src="https://via.placeholder.com/150" class="card-img-top" alt="Placeholder Image"> <div class="card-body"> <h5 class="card-title">Card One</h5> <p class="card-text">This is the first card in a card group.</p> </div> </div> <div class="card"> <img src="https://via.placeholder.com/150" class="card-img-top" alt="Placeholder Image"> <div class="card-body"> <h5 class="card-title">Card Two</h5> <p class="card-text">This card shares the same height as the first.</p> </div> </div> <div class="card"> <img src="https://via.placeholder.com/150" class="card-img-top" alt="Placeholder Image"> <div class="card-body"> <h5 class="card-title">Card Three</h5> <p class="card-text">All cards line up nicely in a group.</p> </div> </div> </div> <h2 class="mt-5">Card Deck Example</h2> <div class="d-flex justify-content-between"> <div class="card" style="width: 18rem;"> <div class="card-body"> <h5 class="card-title">Deck Card One</h5> <p class="card-text">Cards in a deck have space between them.</p> </div> </div> <div class="card" style="width: 18rem;"> <div class="card-body"> <h5 class="card-title">Deck Card Two</h5> <p class="card-text">They look balanced but separate.</p> </div> </div> <div class="card" style="width: 18rem;"> <div class="card-body"> <h5 class="card-title">Deck Card Three</h5> <p class="card-text">Good for showing distinct items.</p> </div> </div> </div> </main> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> </body> </html>
Bootstrap 5 removed .card-deck class; use d-flex and spacing utilities instead for decks.
Always add alt text to images for accessibility.
Use container classes like .container to keep content centered and responsive.
Card groups make cards the same height and connect them visually.
Card decks space cards evenly with margin for a balanced look.
Use these to organize multiple cards neatly on your webpage.
Practice
.card-group in Bootstrap?Solution
Step 1: Understand
The.card-groupbehavior.card-groupclass groups cards so they share the same height and appear connected without gaps.Step 2: Compare with other classes
.card-deckspaces cards evenly with margins, not connecting them tightly.Final Answer:
To make all cards the same height and visually connected -> Option DQuick Check:
.card-group= same height + connected cards [OK]
- Confusing card-group with card-deck spacing
- Thinking card-group adds margins between cards
- Assuming card-group creates a carousel
Solution
Step 1: Identify Bootstrap class for card decks
The correct Bootstrap class for card decks iscard-deck, which spaces cards evenly.Step 2: Check other options
card-groupis for connected cards, and the other classes are not valid Bootstrap classes.Final Answer:
<div class='card-deck'> ... </div> -> Option CQuick Check:
Card deck syntax =card-deck[OK]
- Using 'card-group' instead of 'card-deck' for spacing
- Inventing non-existent classes like 'card-container'
- Misspelling class names
.card-group versus .card-deck for three cards side by side?Solution
Step 1: Understand
.card-grouplayout.card-groupmakes cards the same height and connects them visually without gaps.Step 2: Understand
.card-decklayout.card-deckspaces cards evenly with margins, creating gaps between cards.Final Answer:
Cards in.card-grouphave equal height and no gaps;.card-deckcards have gaps and equal spacing -> Option BQuick Check:
Group = connected; Deck = spaced [OK]
- Thinking card-deck removes gaps
- Assuming both have same spacing
- Confusing card-group with card-deck visually
<div class='card-group'> <div class='card'>Card 1</div> <div class='card'>Card 2</div> <div class='card'>Card 3</div> </div>
What is the issue?
Solution
Step 1: Identify the class used
The code usescard-group, which connects cards without spacing.Step 2: Choose correct class for spacing
To space cards evenly with margins,card-deckshould be used instead.Final Answer:
You should usecard-deckinstead ofcard-groupfor even spacing -> Option AQuick Check:
Spacing needscard-decknotcard-group[OK]
- Adding row or col classes unnecessarily
- Thinking container class controls card spacing
- Confusing card-group and card-deck roles
Solution
Step 1: Understand requirements
You want cards with equal height and even spacing with margin between them.Step 2: Match Bootstrap classes to needs
.card-deckspaces cards evenly with margin and keeps them balanced in height.Step 3: Evaluate other options
.card-groupconnects cards without margin;.card-columnscreates masonry layout, not equal height rows.Final Answer:
Use.card-deckto space cards evenly with margin and equal height -> Option AQuick Check:
Even spacing + equal height =card-deck[OK]
- Using card-group expecting margin spacing
- Using card-columns which stacks cards unevenly
- Not combining with grid classes properly
Ready to prove it?
Pass the test and this pattern moves unknown
