Cards

Source: https://getbootstrap.com/docs/6.0/components/card

Bootstrap’s cards provide a flexible and extensible content container with multiple variants and options.

Cards are flexible and extensible content containers with support for headers and footers, a wide variety of content, contextual background colors, and additional display options. Cards have no fixed width to start, so they’ll naturally fill the width of their parent element, or slot into your grid columns.

<div class="card-body"> <h4 class="card-title">Card title</h4> <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card’s content.</p> <a href="#" class="btn-solid theme-primary">Go somewhere</a> </div> </section>`} />

How it works

Cards are built with as little markup and styles as possible, but still manage to deliver a ton of control and customization.

  • Cards are flexbox containers, so they offer easy alignment via flexbox utilities and grid column classes.

  • .card has no default padding, you need .card-body for that. Use it as a modifier class or a child element alongside headers, footers, images, and more. This allows greater flexibility with the least amount of overhead.

  • Cards have no margin by default. Use margin utilities or gap utilities as needed.

  • Cards can contain text, images, lists, and most other HTML.

  • Choose semantic HTML that fits the content. We use <div>s for simplicity's sake in our documentation, but you can also use <section>, <article>, etc.

Content types

Body

The building block of a card is the .card-body. Use it whenever you need a padded section within a card.

<div class="card-body"> This is some text within a card body. </div> </div>`} />

For simple cards, you can use the .card-body class directly on the card element.

This is some text within a card body. </div>`} />

Card bodies arrange their direct children in a column and apply a consistent gap. Use these optional classes as content hooks.

  • For a title, use .card-title.
  • For a subtitle, use .card-subtitle. It reduces the gap above the subtitle.
  • For text, use .card-text.

Use type and color utilities as needed. Links need no card-specific class.

<div class="card-body"> <h4 class="card-title">Example card title</h4> <p class="card-subtitle fg-3">With a card subtitle</p> <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card’s content.</p> <a href="#">Card link</a> </div> </div>`} />

Images

Place images anywhere in a card and style as you like.

<div class="card-body"> <h5 class="mt-2 mb-0">Image within the body</h5> <p class="card-text fg-2">Some quick example text to build on the card title and make up the bulk of the card’s content.</p> <small class="fg-3">Last updated 3 mins ago</small> </div> </div>`} />

Use .card-img-top and .card-img-bottom to round the top and bottom corners of the image.

<div class="card-body"> <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card’s content.</p> </div> </div> <div class="card" style="width: 18rem;"> <div class="card-body"> <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card’s content.</p> </div> </div>`} />

List groups

When your card only contains a list group—no header, footer, or body—use a .list-group on its own. A card already draws an outer border, so a default list group inside a card would double that border.

<li class="list-group-item">An item</li> <li class="list-group-item">A second item</li> <li class="list-group-item">A third item</li> </ul>`} />

When you mix a list group with other card sub-components, add .list-group-flush to drop the list’s own outer border.

<div class="card-header"> Featured </div> <ul class="list-group list-group-flush"><!-- [!code highlight] --> <li class="list-group-item">An item</li> <li class="list-group-item">A second item</li> <li class="list-group-item">A third item</li> </ul> </div>`} />

<ul class="list-group list-group-flush"><!-- [!code highlight] --> <li class="list-group-item">An item</li> <li class="list-group-item">A second item</li> <li class="list-group-item">A third item</li> </ul> <div class="card-footer"> Card footer </div> </div>`} />

Kitchen sink

Mix and match multiple content types to create the card you need, or throw everything in there. Shown below are image styles, blocks, text styles, and a list group—all wrapped in a fixed-width card.

<div class="card-body"> <h4 class="card-title">Card title</h4> <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card’s content.</p> </div> <ul class="list-group list-group-flush"> <li class="list-group-item">An item</li> <li class="list-group-item">A second item</li> <li class="list-group-item">A third item</li> </ul> <div class="card-body flex-row gap-4"> <a href="#">Card link</a> <a href="#">Another link</a> </div> </div>`} />

Add an optional header and/or footer within a card.

<div class="card-header"> Featured </div> <div class="card-body"> <h4 class="card-title">Special title treatment</h4> <p class="card-text">With supporting text below as a natural lead-in to additional content.</p> <a href="#" class="btn-solid theme-primary">Go somewhere</a> </div> </div>`} />

Card headers can be styled by adding .card-header to <h*> elements.

<h5 class="card-header">Featured</h5> <div class="card-body"> <h4 class="card-title">Special title treatment</h4> <p class="card-text">With supporting text below as a natural lead-in to additional content.</p> <a href="#" class="btn-solid theme-primary">Go somewhere</a> </div> </div>`} />

<div class="card-header"> Quote </div> <div class="card-body"> <figure> <blockquote class="blockquote"> <p>A well-known quote, contained in a blockquote element.</p> </blockquote> <figcaption class="blockquote-footer"> Someone famous in <cite title="Source Title">Source Title</cite> </figcaption> </figure> </div> </div>`} />

<Example code={&lt;div class="card text-center">&lt;!-- [!code highlight] --> &lt;div class="card-header"> Featured &lt;/div> &lt;div class="card-body"> &lt;h4 class="card-title">Special title treatment&lt;/h4> &lt;p class="card-text">With supporting text below as a natural lead-in to additional content.&lt;/p> &lt;a href="#" class="btn-solid theme-primary mx-auto">Go somewhere&lt;/a>&lt;!-- [!code highlight] --> &lt;/div> &lt;div class="card-footer fg-2"> 2 days ago &lt;/div> &lt;/div>} />

Width

Cards assume no specific width to start, so they’ll be 100% wide unless otherwise stated. You can change this as needed with custom CSS, grid classes, grid Sass mixins, or utilities.

Grid

Using the grid, wrap cards in columns and rows as needed.

<div class="sm:col-6 mb-3 sm:mb-0"> <div class="card"> <div class="card-body"> <h4 class="card-title">Card title</h4> <p class="card-text">With supporting text below as a natural lead-in to additional content.</p> <a href="#" class="btn-solid theme-primary">Go somewhere</a> </div> </div> </div> <div class="sm:col-6"> <div class="card"> <div class="card-body"> <h4 class="card-title">Card title</h4> <p class="card-text">With supporting text below as a natural lead-in to additional content.</p> <a href="#" class="btn-solid theme-primary">Go somewhere</a> </div> </div> </div> </div>`} />

Utilities

Use our handful of available sizing utilities to quickly set a card’s width.

<div class="card-body"> <h4 class="card-title">Card title</h4> <p class="card-text">With supporting text below as a natural lead-in to additional content.</p> <a href="#" class="btn-solid theme-primary">Button</a> </div> </div>

<div class="card w-50"> <div class="card-body"> <h4 class="card-title">Card title</h4> <p class="card-text">With supporting text below as a natural lead-in to additional content.</p> <a href="#" class="btn-solid theme-primary">Button</a> </div> </div>`} />

Custom CSS

Use custom CSS in your stylesheets or as inline styles to set a width.

<div class="card-body"> <h4 class="card-title">Card title</h4> <p class="card-text">With supporting text below as a natural lead-in to additional content.</p> <a href="#" class="btn-solid theme-primary">Go somewhere</a> </div> </div>`} />

Add some navigation to a card’s header (or block) with Bootstrap’s nav components.

<div class="card-header"> <ul class="nav nav-tabs card-header-tabs"> <li class="nav-item"> <a class="nav-link active" aria-current="true" href="#">Active</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Link</a> </li> <li class="nav-item"> <a class="nav-link disabled" aria-disabled="true">Disabled</a> </li> </ul> </div> <div class="card-body"> <h5 class="card-title">Special title treatment</h5> <p class="card-text">With supporting text below as a natural lead-in to additional content.</p> <a href="#" class="btn-solid theme-primary mx-auto">Go somewhere</a> </div> </div>`} />

This works with .nav-pills as well.

<div class="card-header"> <ul class="nav nav-pills"> <li class="nav-item"> <a class="nav-link active" href="#">Active</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Link</a> </li> <li class="nav-item"> <a class="nav-link disabled" aria-disabled="true">Disabled</a> </li> </ul> </div> <div class="card-body"> <h5 class="card-title">Special title treatment</h5> <p class="card-text">With supporting text below as a natural lead-in to additional content.</p> <a href="#" class="btn-solid theme-primary mx-auto">Go somewhere</a> </div> </div>`} />

Images

Cards include a few options for working with images. Choose from appending “image caps” at either end of a card, overlaying images with card content, or simply embedding the image in a card.

Image caps

Similar to headers and footers, cards can include top and bottom “image caps”—images at the top or bottom of a card.

<div class="card-body"> <h4 class="card-title">Card title</h4> <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> <p class="card-text"><small class="fg-2">Last updated 3 mins ago</small></p> </div> </div> <div class="card"> <div class="card-body"> <h4 class="card-title">Card title</h4> <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> <p class="card-text"><small class="fg-2">Last updated 3 mins ago</small></p> </div> </div>`} />

Image overlays

Turn an image into a card background and overlay your card’s text. Depending on the image, you may or may not need additional styles or utilities.

<div class="card-img-overlay"> <h4 class="card-title">Card title</h4> <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> <p class="card-text"><small>Last updated 3 mins ago</small></p> </div> </div>`} />