0
0
BootstrapHow-ToBeginner · 3 min read

How to Create a Horizontal Card in Bootstrap Easily

To create a horizontal card in Bootstrap, use the card component combined with d-flex and flex-row classes to arrange content side by side. Place the image and card body inside a flex container to display them horizontally.
📐

Syntax

A horizontal card in Bootstrap uses the card class as the container. Inside, use d-flex and flex-row on a wrapper div to align child elements horizontally. Typically, place an <img> with a custom class or inline sizing on one side, and the card-body on the other.

This layout uses Bootstrap's flexbox utilities to create a side-by-side card structure.

html
<div class="card">
  <div class="d-flex flex-row">
    <img src="image.jpg" alt="..." style="width: 150px;">
    <div class="card-body">
      <h5 class="card-title">Card title</h5>
      <p class="card-text">Some quick example text.</p>
    </div>
  </div>
</div>
Output
A card with an image on the left and text content on the right, arranged horizontally.
💻

Example

This example shows a complete horizontal card with an image on the left and text on the right. It uses Bootstrap 5 classes for layout and styling. The card is responsive and the image size is controlled with inline style.

html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Bootstrap Horizontal Card Example</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
  <div class="container my-4">
    <div class="card">
      <div class="d-flex flex-row">
        <img src="https://via.placeholder.com/150" alt="Sample Image" style="width: 150px; object-fit: cover;">
        <div class="card-body">
          <h5 class="card-title">Horizontal Card Title</h5>
          <p class="card-text">This is an example of a horizontal card using Bootstrap's flex utilities to place the image and text side by side.</p>
          <a href="#" class="btn btn-primary">Go somewhere</a>
        </div>
      </div>
    </div>
  </div>
</body>
</html>
Output
A horizontal card with a 150px wide image on the left and card content with title, text, and button on the right, displayed side by side.
⚠️

Common Pitfalls

  • Not using d-flex and flex-row causes the card content to stack vertically instead of horizontally.
  • Forgetting to set a fixed width on the image can make the layout uneven or cause the image to stretch.
  • Using card-img-top instead of a custom class or inline style places the image above the text, not side by side.
  • Not wrapping the image and body inside a flex container breaks the horizontal layout.
html
<!-- Wrong: image above text -->
<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>
  </div>
</div>

<!-- Right: image and text side by side -->
<div class="card">
  <div class="d-flex flex-row">
    <img src="image.jpg" alt="..." style="width: 150px;">
    <div class="card-body">
      <h5 class="card-title">Title</h5>
      <p class="card-text">Text</p>
    </div>
  </div>
</div>
📊

Quick Reference

Use these Bootstrap classes and tips for horizontal cards:

  • card: main container
  • d-flex flex-row: makes children horizontal
  • Set fixed width on image (e.g., style="width: 150px;")
  • card-body: holds text content
  • Use object-fit: cover; on images for neat cropping

Key Takeaways

Use Bootstrap's flexbox classes d-flex and flex-row to arrange card content horizontally.
Wrap the image and card body inside a flex container to create the horizontal layout.
Set a fixed width on the image to keep the card balanced and visually appealing.
Avoid using card-img-top for horizontal cards as it places the image above the text.
Use object-fit: cover; on images to maintain aspect ratio and cropping.