Bootstrap 4 Javascript AJAX jQuery HTML PHP Example MORE

How to create cards in Bootstrap 4


Basic Card

The basic card is created with the .card class, and content inside the card has a .card-body class:

Example

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap 4 Basic Card</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body> 
 
<div class="container">
  <h2>Basic Card</h2>
  <div class="card">
    <div class="card-body">Basic card</div>
  </div>
</div>

</body>
</html>

Run it Yourself »

Card titles, text, and links

.card-title to add card titles to any heading element. The .card-text class is used to remove bottom margins for a <p> element if it is the last child (or the only one) inside .card-body. The .card-link class adds a blue color to any link, and a hover effect.

Example

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap 4 Card titles, text, and links Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
 
<div class="container">
  <h2>Card titles, text, and links</h2>
  <div class="card">
    <div class="card-body">
      <h4 class="card-title">Card title</h4>
      <p class="card-text">studen tutorial</p>
      <a href="#" class="card-link">link-1</a>
      <a href="#" class="card-link">link-2</a>
    </div>
  </div>
</div>

</body>
</html>

Run it Yourself »

Card images

1- .card-img-top or .card-img-bottom to an <img> to place the image at the top or at the bottom inside the card.

2- Turn an image into a card background and use .card-img-overlay to add text on top of the image:

Example

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap 4 Card image overlays Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
 
<div class="row">
  <div class="col-sm-6">
  <h2>Card Image</h2>
     <div class="card" style="width:400px">
        <img class="card-img-top" src="http://tutorialskill.com/avtar.png" alt="Card image" style="width:100%">
        <div class="card-body">
          <h4 class="card-title">Alexa</h4>
          <p class="card-text">Some example text some example text. John Doe is an architect and engineer</p>
          <a href="#" class="btn btn-primary">View Profile</a>
        </div>
      </div>
  </div>

</div>

</body>
</html>

Run it Yourself »

Card image overlays

1- Turn an image into a card background and use .card-img-overlay to add text on top of the image:

Example

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap 4 Card image overlays Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
 
<div class="row">
  <div class="col-sm-6">
  <h2>Card Image Overlays</h2>
    <div class="card img-fluid" style="width:400px">
      <img class="card-img-top" src="http://tutorialskill.com/avtar.png" alt="Card image" style="width:400px">
      <div class="card-img-overlay">
        <h4 class="card-title">John Doe</h4>
        <p class="card-text">Some example text some example text. Some example text some example text. 
        Some example text some example text. Some example text some example text.</p>
        <a href="#" class="btn btn-primary">See Profile</a>
      </div>
    </div>
  </div>
</div>

</body>
</html>
Run it Yourself »

Card Deck

.card-deck class creates a grid of cards that are of equal height and width. The layout will automatically adjust as you insert more cards.

Example

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap 4 Card Deck Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body> 
 
<div class="container">
  <h2>Card Deck</h2>
  <div class="card-deck">
    <div class="card bg-danger">
      <div class="card-body text-center">
        <p class="card-text">Some text inside the first card</p>
        <p class="card-text">Some more text to increase the height</p>
        <p class="card-text">Some more text to increase the height</p>
        <p class="card-text">Some more text to increase the height</p>
      </div>
    </div>
    <div class="card bg-info">
      <div class="card-body text-center">
        <p class="card-text">Some text inside the second card</p>
      </div>
    </div>
    <div class="card bg-warning">
      <div class="card-body text-center">
        <p class="card-text">Some text inside the third card</p>
      </div>
    </div>
    <div class="card bg-primary">
      <div class="card-body text-center">
        <p class="card-text">Some text inside the fourth card</p>
      </div>
    </div>  
  </div>
</div>

</body>
</html>

Run it Yourself »