How to create a grid of cards in Bootstrap?
To create a card grid in Bootstrap, you need to use its responsive grid system to combine the card components. 1. Use container, row and col-* class layouts to place the card into the column to achieve responsive arrangement; 2. Control the number of cards per row under different screens by adjusting col-12, col-md-6, col-lg-4, col-xl-3 and other classes; 3. To make the cards highly consistent, you can add h-100 on the card class; 4. It is recommended to use gap classes such as g-4 instead of mb-4 to set the spacing on the row, so as to build a neat and adaptive card grid layout.
Creating a grid of cards in Bootstrap is straightforward using its responsive grid system ( row
, col
) combined with the card
component. Here's how to do it properly in modern Bootstrap (v5 ).

1. Use Bootstrap's Grid with Card Components
Bootstrap's grid relies on container
, row
, and col-*
classes. Cards should be placed inside columns to ensure proper spacing and responsiveness.
<div class="container"> <div class="row"> <div class="col-md-4 mb-4"> <div class="card"> <img class="card-img-top lazy" src="/static/imghw/default1.png" data-src="image1.jpg" alt="How to create a grid of cards in Bootstrap?"> <div class="card-body"> <h5 class="card-title">Card 1</h5> <p class="card-text">Some quick example text.</p> <a href="#" class="btn btn-primary">Read More</a> </div> </div> </div> <div class="col-md-4 mb-4"> <div class="card"> <img class="card-img-top lazy" src="/static/imghw/default1.png" data-src="image2.jpg" alt="How to create a grid of cards in Bootstrap?"> <div class="card-body"> <h5 class="card-title">Card 2</h5> <p class="card-text">Some quick example text.</p> <a href="#" class="btn btn-primary">Read More</a> </div> </div> </div> <div class="col-md-4 mb-4"> <div class="card"> <img class="card-img-top lazy" src="/static/imghw/default1.png" data-src="image3.jpg" alt="How to create a grid of cards in Bootstrap?"> <div class="card-body"> <h5 class="card-title">Card 3</h5> <p class="card-text">Some quick example text.</p> <a href="#" class="btn btn-primary">Read More</a> </div> </div> </div> </div> </div>
✅ This creates a responsive 3-column layout on medium screens and above. On smaller screens, cards stack vertically.
2. Control Responsive Behavior
Adjust the col-*
classes to change how many cards appear per row at different breakpoints:
-
col-12
: 1 card per row (mobile) -
col-md-6
: 2 per row on medium -
col-lg-4
: 3 per row on large -
col-xl-3
: 4 per row on extra large
Example for 4 cards per row on large screens:

<div class="row"> <div class="col-12 col-sm-6 col-md-4 col-lg-3 mb-4"> <div class="card"> <div class="card-body"> <h5 class="card-title">Card</h5> <p class="card-text">Content here.</p> </div> </div> </div> <!-- Repeat for other cards --> </div>
This gives you a flexible, responsive card grid.
3. Equal Height Cards (Optional)
If cards have different content lengths, their heights may vary. Use h-100
to make them stretch to full column height:
<div class="col-md-4 mb-4"> <div class="card h-100"> <div class="card-body"> <h5 class="card-title">Card Title</h5> <p class="card-text">This card will match the height of the tallest in the row.</p> </div> </div> </div>
Add h-100
to all cards in the same row for uniform height.
4. Add Gaps Between Cards (Modern Approach)
Use Bootstrap's g-*
(gap) utilities instead of manual margins:
<div class="row g-4"> <div class="col-md-4"> <div class="card"> <!-- Card content --> </div> </div> <!-- More cards --> </div>
This automatically adds spacing between columns and rows without needing
mb-4
.
Key Tips:
- Always wrap cards in
col
classes. - Use
mb-4
org-3/g-4
for spacing. - Use
h-100
for equal height. - Choose
col-*
sizes based on how many cards per row you want at each screen size.
Basically, it's just Bootstrap's grid doing the layout — cards go inside columns. Doesn't get much simpler than that.
The above is the detailed content of How to create a grid of cards in Bootstrap?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

There are three ways to install and use BootstrapIcons: 1. Use CDN and add links to the HTML head; 2. Install through npm, suitable for modern projects such as React and Vue. You need to run npminstallbootstrap-icons and import CSS; 3. Manually download SVG or font files and import them. When using it, you can add bi and icon name classes (such as bi-heart) to insert icons. You can also use other inline elements such as span. It is recommended to use SVG files for better performance and customization capabilities. You can adjust the size through bi-lg, bi-2x and other classes, and use Bootstrap text such as text-danger.

The key to adding a search form in the Bootstrap navigation bar is to have clear structure and correct use of class names. 1. Use d-flex to arrange form elements horizontally, form-control and btn classes are used for input boxes and buttons respectively; 2. Use ms-auto or me-auto to control form alignment to achieve left or right layout; 3. Use w-100 and flex-grow-1 to optimize mobile display to avoid layout confusion; 4. Select the search box position according to the scene. Common practices include placing it on the right, in the middle of navigation or in the collapsed menu; 5. If complex interactions are automatically completed, additional JS is required. By reasonably combining the Bootstrap classes, responsive search boxes can be implemented without complex code.

TodisableaBootstrapbutton,addthedisabledattributeforelements:DisabledButton,whichgraysoutthebutton,preventsclicks,andappliesthecorrectvisualstateautomaticallyviaBootstrap’sstyling.2.Forelementsstyledasbuttons,useclass="disabled"instead,sinc

Bootstrap5doesnotrequirejQuery,asithasbeencompletelyremovedtomaketheframeworklighterandmorecompatiblewithmodernJavaScriptpractices.Theremovalwaspossibleduetodroppedsupportforolderbrowsers,enablingtheuseofmodernES6 JavaScriptfeaturesforbetterperforman

Adjusting the height of the Bootstrap navigation bar can be achieved by the following methods: 1. Use custom CSS to modify the padding-top and padding-bottom values of .navbar to directly control the height; 2. Adjust the font size and line height of .navbar-nav.nav-link indirectly change the height to enhance responsive adaptability; 3. Set styles for .navbar-brand and .nav-item separately, such as height, line-height or use flex layout to optimize vertical alignment; 4. Use Bootstrap's built-in spacing tools such as p-3, py-4, etc. to quickly adjust the inner margins to affect the overall height. Palm

TomakeanimageresponsiveinBootstrap,addthe.img-fluidclasstothetag;thisappliesmax-width:100%andheight:auto,ensuringtheimagescalesproportionallywithinitscontainerwithoutoverflowing;1.Use;2.Worksinsidegrids,cards,oranycontainer;3.Avoidfixedwidthsthatcanb

To trigger the Bootstrap modal box, first make sure to use the correct data properties and load the necessary scripts. 1. Add data-bs-toggle="modal" and data-bs-target="#modalId" attributes to the button to ensure that its value matches the modal box ID; 2. Make sure that the page contains Popper.js and BootstrapJS files and loads in order; 3. If JavaScript control is required, instantiate it through newbootstrap.Modal() and call the show() method; 4. Check whether the modal box HTML is in the DOM, whether the ID matches, and belongs.

The key to using Bootstrap forms is to master its structure and use of classes. 1. The basic form structure uses form-control, form-label, form-text and form-check to style input, label, help text and check boxes; 2. Horizontal forms are displayed in line with labels and controls by combining grid systems (such as col-sm-*), and inline forms use practical classes such as d-flex to replace the removed form-inline in Bootstrap5; 3. Form verification uses is-valid or is-invalid classes to match valid-feedback and invalid-feedback to display inversely.
