Bootstrap 4 Card

In Bootstrap 4, a card is a bordered box with padding around its content. It has options for headers, footers, colors, content, etc. The card provides the link, title, image, and text of the content. The card shows form, table, and complicated content systematically. We can create a grid system or group of cards in a single column.

Types of cards

There are numerous types of cards used on web pages. The following table shows the syntax and description of several Bootstrap4 cards.

Bootstrap4 cardSyntaxDescription
Basic card<div class = "card"> <div class = "card-body"> Basic Bootstrap4 Card </div> </div>  The bootstrap 4 shows basic card and its body in web page.
Primary card<div class = "card bg-primary"> <div class = "card-body"> primary Bootstrap4 Card </div> </div>  The card shows in a blue color. It indicates important content for the page.
Secondary card<div class = "card bg-secondary"> <div class = "card-body"> Secondary  Bootstrap4 Card </div> </div>  The card shows in a grey color.
Success card<div class = "card bg-success"> <div class = "card-body"> Success Bootstrap4 Card </div> </div>  The card shows in green color.
Information card<div class = "card bg-info"> <div class = "card-body"> Information Bootstrap4 Card </div> </div>  The card shows in a light blue color.
Warning card<div class = "card bg-warning"> <div class = "card-body"> Warning Bootstrap4 Card </div> </div>  The card shows in yellow color.
Danger card<div class = "card bg-danger"> <div class = "card-body"> Danger Bootstrap4 Card </div> </div>The card shows in a red color
Dark card<div class = "card bg-dark"> <div class = "card-body"> Dark Bootstrap4 Card </div> </div>  The card shows in a dark grey color
Light card<div class = "card bg-light"> <div class = "card-body"> Light Bootstrap4 Card </div> </div>  The card shows in a white or light grey color.

Contextual Bootstrap4 cards

The contextual cards show their color, format, and texture with classes. The basic card requires card class and card body class. The bootstrap4 card uses the .card class with other contextual classes.

Example

The following example shows different type of the cards.

<!DOCTYPE html>

<html lang="en">

<head>

  <title>Bootstrap4 cards Example</title>

  <meta charset="utf-8">

  <meta name="viewport" content="width=device-width, initial-scale=1">

  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css">

  <script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.slim.min.js"></script>

  <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>

  <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.bundle.min.js"></script>

</head>

<body>

<div class="container" id="cards">

<br>

  <div class = "card">

<div class = "card-body text-dark"> Basic Bootstrap4 Card </div>

</div>

<br>

<div class = "card bg-primary">

<div class = "card-body text-white"> primary Bootstrap4 Card </div>

</div>

<br>

<div class = "card bg-secondary">

<div class = "card-body text-white"> Secondary  Bootstrap4 Card </div>

</div>

<br>

<div class = "card bg-success">

<div class = "card-body text-white"> Success Bootstrap4 Card </div>

</div>

<br>

<div class = "card bg-warning">

<div class = "card-body"> Warning Bootstrap4 Card </div>

</div>

<br>

<div class = "card bg-info">

<div class = "card-body"> Information Bootstrap4 Card </div>

</div>

<br>

<div class = "card bg-dark">

<div class = "card-body text-white"> Dark Bootstrap4 Card </div>

</div>

<br>

<div class = "card bg-danger">

<div class = "card-body text-white"> Danger Bootstrap4 Card </div>

</div>

<br>

</div>

</body>

</html>

Output

The below image shows the relevant output of the given an example.

Bootstrap 4 Card

Cards Header and Footer

The .card-header and .card-footer classes add a heading and footer to the card, respectively.

Bootstrap4 cardSyntaxDescription
Header<div class = "card-header"> Heading content </div>  The card header provides the heading of the card body.  
Footer<div class = "card-footer"> Footer content </div>  The card header provides footer content for the card body.  

Example

The following example shows header and footer of the cards. This example uses light card class with the header and footer.

<!DOCTYPE html>

<html lang="en">

<head>

<title>Bootstrap4 cards Example</title>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css">

<script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.slim.min.js"></script>

<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.bundle.min.js"></script>

</head>

<body>

<div class="container" id="cards">

<h4> Hearder and Footer</h4>

<div class = "card bg-light">

<div class = "card-header"> Registration form </div>

<div class = "card-body">

<form>

<div class = "form-group">

<label for = "uId"> User Id:</label>

<input type = "input" class="form-control" placeholder="Enter User Id" id="uId">

</div>

<div class = "form-group">

<label for = "pass"> Password: </label>

<input type = "input" class="form-control" placeholder="Enter User password"    id="pass">

</div>

<input type = "submit" class="btn btn-secondary">

</form>

</div>

<div class="card-footer"> It creates @2022</div>

</div>

<br>

</div>

</body>

</html>

Output

The below image shows the header and footer output of the given an example.

Bootstrap 4 Card

Title, Text, Images, and Links

The bootstrap4 card contains a web page's link, title, image, and text. The following table shows the syntax and description of the card functions.

Bootstrap4 cardSyntaxDescription
Title<h1 class = "card-title"> Content Title </h1>  The card provides the title for the web content.  
Text<p class = "card-text"> Content data </p>  The card provides the title for the web content.    
Image<img class = "card-img-top" src="path/image.png" alt = "image name"> OR <img class = "card-img-bottom" src="path/image.png" alt = "image name">The card contains images either top   side or bottom side of the card body.    
Link<a href = "javatpoint.com" class = "card-link"> Web page link </a>  The card provides a link to the other web pages.    

Example

The following example shows how to create title, texts, link and image in the cards.

<!DOCTYPE html>

<html lang="en">

<head>

<title>Bootstrap4 cards Example</title>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css">

<script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.slim.min.js"></script>

<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.bundle.min.js"></script>

<style>

img{

border:2px solid grey;

}

.container{

width:30%;

height:30%;

}

</style>

</head>

<body>

<br>

<div class="container" id="cards">

<div class = "card">

<div class = "card-body">

<h5 class = "card-title"> Content Title </h5>

<p class = "card-text">

The card contains text, title, image, links and other functions.

</p>

<b> Card link: </b>

<a href = "https://www.javatpoint.com/" class = "card-link"> Web page link </a> <br>

<b> Card image </b> <br>

<img class = "card-img-bottom" src="C:\Users\hp\Pictures\Screenshots\bootstrap_card.png" alt = "Card's Type">

</div>

</div>

</div>

</body>

</html>

Output

Bootstrap 4 Card

Bootstrap4 Cards column

The .card-columns class includes multiple cards to contain different type of the data.

Bootstrap4 cardSyntaxDescription
Card column<div class = "card-columns"> Heading content </div>  The card columns contain multiple cards.  

Example

The following example shows different type of the cards in single column.

<!DOCTYPE html>

<html lang="en">

<head>

  <title>Bootstrap4 cards Example</title>

  <meta charset="utf-8">

  <meta name="viewport" content="width=device-width, initial-scale=1">

  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css">

  <script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.slim.min.js"></script>

  <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>

  <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.bundle.min.js"></script>

</head>

<body>

<div class="container w-50" id="cards">

<div class="card-columns">

  <div class = "card">

<div class = "card-body text-dark"> Basic Bootstrap4 Card </div>

</div>

<div class = "card bg-primary">

<div class = "card-body text-white"> primary Bootstrap4 Card </div>

</div>

<div class = "card bg-secondary">

<div class = "card-body text-white"> Secondary Card </div>

</div>

<div class = "card bg-success">

<div class = "card-body text-white"> Success Bootstrap4 Card </div>

</div>

<div class = "card bg-warning">

<div class = "card-body"> Warning Bootstrap4 Card </div>

</div>

<div class = "card bg-info">

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

</div>

<div class = "card bg-dark">

<div class = "card-body text-white"> Dark Bootstrap4 Card </div>

</div>

<div class = "card bg-danger">

<div class = "card-body text-white"> Danger Bootstrap4 Card </div>

</div>

<div class = "card bg-light">

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

</div>

</div>

</div>

</body>

</html>

Output

Bootstrap 4 Card

Conclusion

Bootstrap4 card help to display multiple contents and its features easily. The card shows complicated data in a simple format using several classes. The card contains essential user interactive features to make a user-friendly web page.


Related Topics

Bootstrap Multiselect Dropdown

What is a multi-select Dropdown? Multi-select dropdown lists are used when we want to select multiple options for a particular record. Usually, dropdown lists provide the feature of choosing just one value...

4 minutes read.

Bootstrap 4 Tooltip

Bootstrap 4 Tooltip Tooltip Bootstrap 4 offers a tooltip component, a small popup box that appears when you move the cursor over an element such as buttons or any highlighted element. It...

3 minutes read.

Bootstrap 4 Form

Bootstrap 4 Forms Bootstrap 4 provides forms, which are one of the essential components for web pages and web applications. It is an input-based component, used to collect user data with the help of...

8 minutes read.

Bootstrap 4 Scrollspy

Bootstrap 4 Scrollspy Bootstrap 4 offers a scrollspy component that is used to make the website more attractive and eye-catching. Basically, the scrollspy is used on the single-page website. The scrollspy highlights the nav...

5 minutes read.

Bootstrap Notification Bubble

What is a notification bubble? Bubbles are built into the Notification system. They float on top of the website or the button to indicate pending notifications. Bubbles can be expanded to reveal...

5 minutes read.

Bootstrap 4 Icons

Bootstrap 4 Icons Bootstrap 3 contains the default icon library. But in bootstrap 4, you have to include the external icon library by yourself. Many free icon libraries are available such...

2 minutes read.

Bootstrap 4 Dropdowns

Bootstrap Dropdowns Bootstrap 4 provides a dropdown component, which is a toggle and contextual layout, used to display a predefined list of links. It allows the user to select a value from the dropdown...

15 minutes read.

Dropdown & Dropup

Bootstrap Dropdowns The bootstrap dropdown menu is used to create a toggleable menu. It provides users to choose one value from a predefined list. Before creating dropdown menu, we have to know...

3 minutes read.

Bootstrap 4 Layout

Containers Containers are the essential elements of the bootstrap layout. It is required when we are using a bootstrap grid system. Containers can also be nested, but most layouts do not need nested containers. Bootstrap has...

3 minutes read.

Bootstrap Tabs and Pills

Bootstrap Menus Bootstrap menu is used to create different types of menu. It can created horizontal with its .list-inlineclass. <div class="container">       <h3>Example of Bootstrap Menu</h3>       <ul class="list-inline">         <li><a href="#">Home</a></li>         <li><a href="#">About</a></li>         <li><a href="#">Contact</a></li>         <li><a href="#">services</a></li>       </ul>     </div> Try Now Bootstrap Tabs Bootstrap tabl is look like is menu but there is some difference....

4 minutes read.

Bootstrap Searchable Dropdown Menu

Searchable Dropdown Menu When we click on the dropdown button/arrow in this dropdown menu, an input field will pop up with all the dropdown items listing inside. If we type in...

5 minutes read.

Bootstrap Badges and Labels

Bootstrap Badges Bootstrap Badges are numerical indicators. It is used to show that how many items are associated with a link.The .badge class is used to create of Bootstrap Badges. Let us see...

2 minutes read.

Bootstrap 4 navbar

A navigation navbar or navbar uses in every website to make it more user-friendly. Navigating through the website is easier, and the user can instantly search for the topic of...

8 minutes read.

Bootstrap 4 Tutorial

What is Bootstrap? Bootstrap is a CSS (Cascading Style Sheets) framework, which is used to develop a responsive website. It is an open-source and mobile-first front-end framework. It has design templates that are based...

4 minutes read.

Bootstrap 4 Alerts

Bootstrap 4 Alerts Bootstrap 4 offers alerts that are used to provide feedback messages on the user’s actions. There is no boundation of text length in the alerts. Alerts can be created...

1 minute read.

Bootstrap 4 Content

Typography Typography is used for styling and formatting the content. It also helps in creating customized headings, sub-headings, lists, paragraphs, etc. Headings Bootstrap 4 offers HTML heading <h1> to <h6> that has bolder...

8 minutes read.

Bootstrap 4 List Groups

Bootstrap 4 List Groups Bootstrap 4 offers List Group component, which is used to display a series of content in an organized way. The most common list group is an unordered...

13 minutes read.

Bootstrap 4 Spinners

Bootstrap 4 offers spinner is a loading indicator that is used to display the loading state of any component or web page. The spinner is also known as a loader...

7 minutes read.

CakePHP Layouts & Elements

A layout includes a presentation code that can be wrapped out in your view. It means that what you want to see in your view should be well-positioned in layout. When you create...

9 minutes read.

Bootstrap 4 Filters

 Bootstrap 4 Filters Bootstrap 4 provides a filter component that is used to search an element from a list, table, etc. Bootstrap does not contain any component or utility that helps...

5 minutes read.