Lesson 19 of 60 – Bootstrap Cards
32%

Bootstrap Cards

Bootstrap cards are flexible content containers used to display information in a clean and organized way. Cards can contain text, images, titles, buttons, links, lists, headers, footers, and many other elements.

Note: A basic Bootstrap card is created using the .card class. Content can be placed inside .card-body, while .card-header and .card-footer can be used for additional sections.

1. What Is a Bootstrap Card?

A Bootstrap card is a flexible container used to present related information as a single visual unit.

<div class="card">

    <div class="card-body">
        This is a Bootstrap card.
    </div>

</div>
This is a Bootstrap card.

Cards are commonly used for products, courses, student profiles, dashboard statistics, blog posts, and services.

2. The .card Class

The .card class creates the outer container of a Bootstrap card.

<div class="card">

    Card content

</div>
Card content

The card itself acts as the main wrapper for all card-related content.

3. The .card-body Class

The .card-body class provides the main content area of a card.

<div class="card">

    <div class="card-body">

        <h5>Course Name</h5>
        <p>Learn HTML and CSS.</p>

    </div>

</div>
Course Name

Learn HTML and CSS.

4. Card Title

Use .card-title for the main title of a card.

<div class="card">

    <div class="card-body">

        <h5 class="card-title">
        Bootstrap Course
        </h5>

    </div>

</div>
Bootstrap Course

5. Card Text

The .card-text class can be used for text content inside a card.

<p class="card-text">
Learn Bootstrap from beginner to advanced level.
</p>

Learn Bootstrap from beginner to advanced level.

6. Card Subtitle

The .card-subtitle class can be used for secondary information below a card title.

<h5 class="card-title">
Bootstrap
</h5>

<h6 class="card-subtitle mb-2 text-body-secondary">
Frontend Framework
</h6>
Bootstrap
Frontend Framework

7. Card Links

The .card-link class styles links inside a card.

<a href="#" class="card-link">
Read More
</a>

<a href="#" class="card-link">
View Course
</a>
HTML Course
Read More View Course

8. Card Header

The .card-header class creates a header section at the top of a card.

<div class="card">

    <div class="card-header">
    Course Information
    </div>

    <div class="card-body">
    Course content goes here.
    </div>

</div>
Course Information
Course content goes here.

9. Card Footer

The .card-footer class creates a footer section at the bottom of a card.

<div class="card">

    <div class="card-body">
    Course content
    </div>

    <div class="card-footer">
    Updated Today
    </div>

</div>
Course content

10. Card with Header and Footer

A card can have both a header and a footer.

<div class="card">

    <div class="card-header">
    Course
    </div>

    <div class="card-body">
    Learn Bootstrap.
    </div>

    <div class="card-footer">
    6 Months
    </div>

</div>
Course
Learn Bootstrap.

11. Card Images

Images can be placed at the top of a card using .card-img-top.

<img src="image.jpg"
class="card-img-top"
alt="Course Image">

Example structure:

<div class="card">

    <img src="image.jpg"
    class="card-img-top"
    alt="Course Image">

    <div class="card-body">
        <h5 class="card-title">
        Web Development
        </h5>
    </div>

</div>

12. Card Image at the Bottom

An image can also be placed at the bottom of a card using .card-img-bottom.

<div class="card">

    <div class="card-body">
        <h5 class="card-title">
        Web Development
        </h5>
    </div>

    <img src="image.jpg"
    class="card-img-bottom"
    alt="Course Image">

</div>

This can be useful when the image should appear after the main content.

13. Card with Button

Buttons can be added to cards for actions such as View Details, Buy Now, Read More, or Enroll.

<div class="card">

    <div class="card-body">

        <h5 class="card-title">
        Python Course
        </h5>

        <p class="card-text">
        Learn Python programming.
        </p>

        <a href="#"
        class="btn btn-primary">
        Enroll Now
        </a>

    </div>

</div>
Python Course

Learn Python programming.

Enroll Now

14. Card with Badge

Badges can be used inside cards to show status or category.

<h5 class="card-title">
Python Course
</h5>

<span class="badge text-bg-success">
Active
</span>
Python Course
Active

15. Card with List Group

A list group can be placed inside a card to display related items.

<div class="card">

    <div class="card-header">
    Course Topics
    </div>

    <ul class="list-group list-group-flush">

        <li class="list-group-item">
        HTML
        </li>

        <li class="list-group-item">
        CSS
        </li>

        <li class="list-group-item">
        JavaScript
        </li>

    </ul>

</div>
Course Topics
  • HTML
  • CSS
  • JavaScript

16. Card with List Group and Footer

A card can contain a list group together with a footer.

<div class="card">

    <div class="card-header">
    Course
    </div>

    <ul class="list-group list-group-flush">

        <li class="list-group-item">
        HTML
        </li>

        <li class="list-group-item">
        CSS
        </li>

    </ul>

    <div class="card-footer">
    Beginner Level
    </div>

</div>
Course
  • HTML
  • CSS

17. Card Background Colors

Bootstrap background utilities can be combined with cards.

<div class="card text-bg-primary">
    <div class="card-body">
    Primary Card
    </div>
</div>

<div class="card text-bg-success">
    <div class="card-body">
    Success Card
    </div>
</div>
Primary Card
Success Card

18. Card Border Colors

Bootstrap border utilities can be used to change the border color of a card.

<div class="card border-primary">

    <div class="card-body">
    Primary Border
    </div>

</div>
Primary Border

19. Card Groups

The .card-group class can be used to join cards into a single connected group.

<div class="card-group">

    <div class="card">
        <div class="card-body">
        Card One
        </div>
    </div>

    <div class="card">
        <div class="card-body">
        Card Two
        </div>
    </div>

</div>
Card One
Card Two

20. Card Grid

Cards can be placed inside Bootstrap's grid system to create responsive layouts.

<div class="row">

    <div class="col-md-4">

        <div class="card">
            <div class="card-body">
            Card One
            </div>
        </div>

    </div>

    <div class="col-md-4">

        <div class="card">
            <div class="card-body">
            Card Two
            </div>
        </div>

    </div>

</div>
Card One
Card Two

21. Equal Height Cards

Bootstrap's grid and flex utilities can help create cards with equal height within a row.

<div class="row">

    <div class="col-md-4 d-flex">

        <div class="card w-100">

            <div class="card-body">
            Card content
            </div>

        </div>

    </div>

</div>

Using d-flex on the column and w-100 on the card can help the card fill the available column width.

22. Horizontal Cards

Cards can also be arranged horizontally using Bootstrap's grid and flex utilities.

<div class="row g-0">

    <div class="col-md-4">
        <img src="image.jpg"
        class="img-fluid"
        alt="Course">
    </div>

    <div class="col-md-8">

        <div class="card-body">

            <h5 class="card-title">
            Web Development
            </h5>

            <p class="card-text">
            Learn modern web development.
            </p>

        </div>

    </div>

</div>

This pattern is useful when an image and content need to appear beside each other on larger screens.

23. Card with Header Navigation

A card header can contain navigation or tabs.

<div class="card-header">

    <ul class="nav nav-tabs card-header-tabs">

        <li class="nav-item">
            <a class="nav-link active"
            href="#">
            Overview
            </a>
        </li>

        <li class="nav-item">
            <a class="nav-link"
            href="#">
            Details
            </a>
        </li>

    </ul>

</div>
Course overview information.

24. Product Card Example

Cards are commonly used to display products or services.

<div class="card">

    <div class="card-body">

        <h5 class="card-title">
        Website Development
        </h5>

        <p class="card-text">
        Professional website development service.
        </p>

        <h5>
        ₹10,500
        </h5>

        <a href="#"
        class="btn btn-primary">
        View Details
        </a>

    </div>

</div>
Website Development

Professional website development service.

₹10,500
View Details

25. Course Card Example

Cards are ideal for displaying courses on an education website.

<div class="card">

    <div class="card-body">

        <span class="badge text-bg-success">
        Popular
        </span>

        <h5 class="card-title mt-2">
        Python Full Stack
        </h5>

        <p class="card-text">
        Learn Python, SQL, Django and web development.
        </p>

        <a href="#"
        class="btn btn-primary">
        Enroll Now
        </a>

    </div>

</div>
Popular
Python Full Stack

Learn Python, SQL, Django and web development.

Enroll Now

26. Student Profile Card

Cards can be used to display student profile information.

<div class="card">

    <div class="card-body">

        <h5 class="card-title">
        Rahul Kumar
        </h5>

        <p class="card-text">
        Student ID: ST101
        </p>

        <p class="card-text">
        Course: ADCA
        </p>

        <span class="badge text-bg-success">
        Active
        </span>

    </div>

</div>
Rahul Kumar

Student ID: ST101

Course: ADCA

Active

27. Card Accessibility

Cards should be structured so that their content remains understandable to all users.

  • Use meaningful headings.
  • Use descriptive alternative text for meaningful images.
  • Keep related information together.
  • Use buttons and links according to their purpose.
  • Do not rely only on color to communicate important information.
  • Keep card content readable on smaller screens.
Tip: A card should organize information, not hide important information behind unnecessary visual elements.

28. Common Card Mistakes

Avoid these common mistakes when designing cards:

  • Putting too much content into one card.
  • Using cards for every small piece of information.
  • Using very large images unnecessarily.
  • Creating too many cards on one screen.
  • Using unclear buttons such as "Click Here".
  • Ignoring responsive behavior.

Cards work best when they group related information clearly.

29. Practical Dashboard Cards

Dashboard applications frequently use cards to display statistics.

<div class="row">

    <div class="col-md-4">

        <div class="card text-bg-primary">

            <div class="card-body">

                <h5>Total Students</h5>
                <h2>250</h2>

            </div>

        </div>

    </div>

    <div class="col-md-4">

        <div class="card text-bg-success">

            <div class="card-body">

                <h5>Active Students</h5>
                <h2>220</h2>

            </div>

        </div>

    </div>

</div>
Total Students

250

Active Students

220

Pending Fees

30

30. Complete Bootstrap Card Example

The following example combines a card image, badge, title, text, button, and footer.

<div class="card" style="max-width:400px;">

    <img src="course.jpg"
    class="card-img-top"
    alt="Course Image">

    <div class="card-body">

        <span class="badge text-bg-success">
        Popular
        </span>

        <h5 class="card-title mt-2">
        Web Development
        </h5>

        <p class="card-text">
        Learn HTML, CSS, JavaScript and Bootstrap.
        </p>

        <a href="#"
        class="btn btn-primary">
        View Course
        </a>

    </div>

    <div class="card-footer">
    Updated Today
    </div>

</div>
Popular
Web Development

Learn HTML, CSS, JavaScript and Bootstrap.

View Course

📌 Key Points

  • Use .card to create a Bootstrap card.
  • Use .card-body for the main card content.
  • Use .card-title for card titles.
  • Use .card-text for card text.
  • Use .card-subtitle for secondary headings.
  • Use .card-link for links inside cards.
  • Use .card-header for the card header.
  • Use .card-footer for the card footer.
  • Use .card-img-top for an image at the top.
  • Use .card-img-bottom for an image at the bottom.
  • Use .card-group to group cards together.
  • Cards can be combined with Bootstrap's grid system.
  • Cards can contain buttons, badges, lists, images, and other components.

🧠 Quick Quiz

Question: Which Bootstrap class is used to create the main content area of a card?