Carousel

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

A slider or slideshow component for cycling through series of content, ranging from products to images and more, one at a time.

How it works

  • Carousel is built on CSS’s scroll-snap, so sliding, touch dragging, momentum, and keyboard scrolling all come from the browser. JavaScript manages autoplay, the previous/next controls, the indicators, and active-slide syncing.

  • Because the slides live in a real scroll container, the carousel can show more than one slide at a time, reveal a “peek” of the neighboring slides, and mix variable-width slides—all controlled with CSS.

  • Carousels can have any number of slides, with just about any content within. Our examples show images and text, but you can put anything you like inside each .carousel-item. We don't support nested carousels.

  • Carousel items or slides do not normalize their dimensions. As such, you may need to use additional utilities or custom styles to appropriately size content. While carousels support previous/next controls and indicators, they’re not explicitly required. Add and customize as you see fit.

  • Some behaviors that need a manually initialized instance before any interaction are autoplay on page load and active-slide syncing as the user scrolls or swipes (the indicators only start tracking the visible slide once an instance exists). Autoplaying carousels with the data-bs-autoplay="true" attribute are initialized automatically on page load; otherwise, initialize with the constructor method. If you’re using autoplaying carousels with the data attribute, don’t explicitly initialize the same carousels with the constructor method.

  • Mark one slide .active to set the starting slide. It seeds the active state that drives indicator syncing and—in .carousel-fade—which slide is shown; if no slide is .active, the carousel starts on the first one. Also be sure to set a unique id on the .carousel for optional controls, especially if you’re using multiple carousels on a single page. Control and indicator elements must have a data-bs-target attribute (or href for links) that matches the id of the .carousel element.

Examples

Top controls

The default carousel has a simple design that you can customize. Controls can be placed anywhere, including outside the inner carousel container. They can sit at the top or bottom of the carousel, with any order of controls and any additional content you may need.

<div class="d-flex justify-content-between align-items-center"> <h5 class="mb-0">Top controls</h5> <div> <button class="btn-icon btn-sm" type="button" data-bs-target="#carouselStacked" data-bs-slide="prev"> <span class="carousel-icon-prev" aria-hidden="true"></span> <span class="visually-hidden">Previous</span> </button> <button class="btn-icon btn-sm" type="button" data-bs-target="#carouselStacked" data-bs-slide="next"> <span class="carousel-icon-next" aria-hidden="true"></span> <span class="visually-hidden">Next</span> </button> </div> </div> <div class="carousel-inner rounded-5"> <div class="carousel-item active"> </div> <div class="carousel-item"> </div> <div class="carousel-item"> </div> </div> </div>`} />

Bottom controls

Similar to the controls on top, but with the controls at the bottom of the carousel and different content.

<div class="carousel-inner rounded-5"> <div class="carousel-item active"> </div> <div class="carousel-item"> </div> <div class="carousel-item"> </div> </div> <div> <button class="btn-icon btn-sm" type="button" data-bs-target="#carouselStackedBottom" data-bs-slide="prev"> <span class="carousel-icon-prev" aria-hidden="true"></span> <span class="visually-hidden">Previous</span> </button> <button class="btn-icon btn-sm" type="button" data-bs-target="#carouselStackedBottom" data-bs-slide="next"> <span class="carousel-icon-next" aria-hidden="true"></span> <span class="visually-hidden">Next</span> </button> </div> </div>`} />

Indicators

Add indicator buttons wherever you want them to reside. With an overlay carousel, place them inside .carousel-overlay-controls, which is positioned over the bottom of the slides—their exact alignment then depends on how you lay out that row (for example, centered between the prev/next controls).

<div class="carousel-inner rounded-5"> <div class="carousel-item active"> </div> <div class="carousel-item"> </div> <div class="carousel-item"> </div> </div> <div class="d-flex justify-content-between align-items-center"> <div> <button class="btn-icon btn-sm" type="button" data-bs-target="#carouselStackedIndicators" data-bs-slide="prev"> <span class="carousel-icon-prev" aria-hidden="true"></span> <span class="visually-hidden">Previous</span> </button> <button class="btn-icon btn-sm" type="button" data-bs-target="#carouselStackedIndicators" data-bs-slide="next"> <span class="carousel-icon-next" aria-hidden="true"></span> <span class="visually-hidden">Next</span> </button> </div> <div class="carousel-indicators"> <button type="button" data-bs-target="#carouselStackedIndicators" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button> <button type="button" data-bs-target="#carouselStackedIndicators" data-bs-slide-to="1" aria-label="Slide 2"></button> <button type="button" data-bs-target="#carouselStackedIndicators" data-bs-slide-to="2" aria-label="Slide 3"></button> </div> </div> </div>`} />

Custom content

You can put any markup you like inside each .carousel-item. Add content, then size and style it with utilities or custom CSS as needed.

<div class="carousel-inner rounded-5"> <div class="carousel-item active"> <div class="d-flex flex-column justify-content-center bg-subtle-primary p-9 bg-1 rounded-5" style="min-height: 320px;"> <h3>Build anything</h3> <p class="fg-emphasis-secondary mb-3">Compose slides from your own markup—text, buttons, cards, or media.</p> <div><a class="btn-solid theme-primary" href="#">Get started</a></div> </div> </div> <div class="carousel-item"> <div class="d-flex flex-column justify-content-center text-center bg-subtle-success p-9 bg-2 rounded-5" style="min-height: 320px;"> <h3>Style it your way</h3> <p class="fg-emphasis-secondary mb-3">Use utilities or custom CSS to size and theme each slide however you need.</p> <div><a class="btn-solid theme-success" href="#">Learn more</a></div> </div> </div> <div class="carousel-item"> <div class="d-flex flex-column justify-content-center text-end bg-subtle-warning p-9 bg-3 rounded-5" style="min-height: 320px;"> <h3>Mix and match</h3> <p class="fg-emphasis-secondary mb-3">Combine custom content with controls, indicators, and the overlay layout.</p> <div><a class="btn-solid theme-inverse" href="#">Browse examples</a></div> </div> </div> </div> <div class="d-flex justify-content-center gap-2"> <button class="btn-icon btn-sm" type="button" data-bs-target="#carouselExampleContent" data-bs-slide="prev" style="--bs-carousel-control-icon-width: 1rem;"> <span class="carousel-icon-prev" aria-hidden="true"></span> <span class="visually-hidden">Previous</span> </button> <button class="btn-icon btn-sm" type="button" data-bs-target="#carouselExampleContent" data-bs-slide="next" style="--bs-carousel-control-icon-width: 1rem;"> <span class="carousel-icon-next" aria-hidden="true"></span> <span class="visually-hidden">Next</span> </button> </div> </div>`} />

Modifiers

Change the default carousel appearance with alternate control placement and animations.

Overlay controls

Add .carousel-overlay to overlay carousel controls on top of the slides. Wrap any controls you want to overlay in .carousel-overlay-controls.

<Example code={&lt;div id="carouselExample" class="carousel carousel-overlay slide">&lt;!--[!code highlight]--> &lt;div class="carousel-inner rounded-5"> &lt;div class="carousel-item active"> &lt;/div> &lt;div class="carousel-item"> &lt;/div> &lt;div class="carousel-item"> &lt;/div> &lt;/div> &lt;div class="carousel-overlay-controls">&lt;!--[!code highlight]--> &lt;div> &lt;button class="btn-icon btn-sm btn-subtle theme-secondary" type="button" data-bs-target="#carouselExample" data-bs-slide="prev"> &lt;span class="carousel-icon-prev" aria-hidden="true">&lt;/span> &lt;span class="visually-hidden">Previous&lt;/span> &lt;/button> &lt;button class="btn-icon btn-sm btn-subtle theme-secondary" type="button" data-bs-target="#carouselExample" data-bs-slide="next"> &lt;span class="carousel-icon-next" aria-hidden="true">&lt;/span> &lt;span class="visually-hidden">Next&lt;/span> &lt;/button> &lt;/div> &lt;div class="carousel-indicators"> &lt;button type="button" data-bs-target="#carouselExample" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1">&lt;/button> &lt;button type="button" data-bs-target="#carouselExample" data-bs-slide-to="1" aria-label="Slide 2">&lt;/button> &lt;button type="button" data-bs-target="#carouselExample" data-bs-slide-to="2" aria-label="Slide 3">&lt;/button> &lt;/div> &lt;/div>&lt;!--[!code highlight]--> &lt;/div>} />

Crossfade

Add .carousel-fade to your carousel to animate slides with a fade transition instead of a slide. Depending on your carousel content (e.g., text only slides), you may want to add .bg-body or some custom CSS to the .carousel-items for proper crossfading. The crossfade is a CSS opacity transition over --bs-carousel-fade-duration, and collapses to an instant swap for users who prefer reduced motion.

<Example code={&lt;div id="carouselExampleFade" class="carousel carousel-fade">&lt;!--[!code highlight]--> &lt;div class="carousel-inner"> &lt;div class="carousel-item active"> &lt;/div> &lt;div class="carousel-item"> &lt;/div> &lt;div class="carousel-item"> &lt;/div> &lt;/div> &lt;div> &lt;button class="btn-icon btn-sm" type="button" data-bs-target="#carouselExampleFade" data-bs-slide="prev"> &lt;span class="carousel-icon-prev" aria-hidden="true">&lt;/span> &lt;span class="visually-hidden">Previous&lt;/span> &lt;/button> &lt;button class="btn-icon btn-sm" type="button" data-bs-target="#carouselExampleFade" data-bs-slide="next"> &lt;span class="carousel-icon-next" aria-hidden="true">&lt;/span> &lt;span class="visually-hidden">Next&lt;/span> &lt;/button> &lt;/div> &lt;/div>} />

Items

Because the carousel is a real scroll container, you can change how many slides are visible and how they’re sized with a few CSS custom properties on the .carousel without writing any JavaScript.

  • --bs-carousel-items sets the number of whole slides visible per view (default 1).
  • --bs-carousel-items-gap sets the space between slides (default 0).
  • --bs-carousel-items-peek sets how much of the neighboring slides to reveal (default 0).

Multiple items

Set --bs-carousel-items to show several slides at once. Combine it with --bs-carousel-items-gap for spacing.

<Example code={&lt;div id="carouselMultiple" class="carousel slide" data-bs-ends="stop" style="--bs-carousel-items: 3; --bs-carousel-items-gap: 1rem;">&lt;!--[!code highlight]--> &lt;div class="d-flex justify-content-between align-items-center"> &lt;h5 class="mb-0">Three at a time&lt;/h5> &lt;div> &lt;button class="btn-icon btn-sm" type="button" data-bs-target="#carouselMultiple" data-bs-slide="prev" style="--bs-carousel-control-icon-width: 1rem;"> &lt;span class="carousel-icon-prev" aria-hidden="true">&lt;/span> &lt;span class="visually-hidden">Previous&lt;/span> &lt;/button> &lt;button class="btn-icon btn-sm" type="button" data-bs-target="#carouselMultiple" data-bs-slide="next" style="--bs-carousel-control-icon-width: 1rem;"> &lt;span class="carousel-icon-next" aria-hidden="true">&lt;/span> &lt;span class="visually-hidden">Next&lt;/span> &lt;/button> &lt;/div> &lt;/div> &lt;div class="carousel-inner"> &lt;div class="carousel-item active">&lt;Placeholder width="260" height="200" class="bd-placeholder-img d-block w-100 rounded-5" color="#fff" background="#777" text="1" />&lt;/div> &lt;div class="carousel-item">&lt;Placeholder width="260" height="200" class="bd-placeholder-img d-block w-100 rounded-5" color="#fff" background="#6c6c6c" text="2" />&lt;/div> &lt;div class="carousel-item">&lt;Placeholder width="260" height="200" class="bd-placeholder-img d-block w-100 rounded-5" color="#fff" background="#666" text="3" />&lt;/div> &lt;div class="carousel-item">&lt;Placeholder width="260" height="200" class="bd-placeholder-img d-block w-100 rounded-5" color="#fff" background="#5c5c5c" text="4" />&lt;/div> &lt;div class="carousel-item">&lt;Placeholder width="260" height="200" class="bd-placeholder-img d-block w-100 rounded-5" color="#fff" background="#555" text="5" />&lt;/div> &lt;div class="carousel-item">&lt;Placeholder width="260" height="200" class="bd-placeholder-img d-block w-100 rounded-5" color="#fff" background="#4c4c4c" text="6" />&lt;/div> &lt;div class="carousel-item">&lt;Placeholder width="260" height="200" class="bd-placeholder-img d-block w-100 rounded-5" color="#fff" background="#444" text="7" />&lt;/div> &lt;/div> &lt;/div>} />

Set --bs-carousel-items inline to control the count, e.g. style="--bs-carousel-items: 3;".

Peeking

Set --bs-carousel-items-peek to reveal a sliver of the previous and next slides, hinting that there’s more to scroll.

<Example code={&lt;div id="carouselPeek" class="carousel slide" data-bs-ends="stop" style="--bs-carousel-items-peek: 3rem; --bs-carousel-items-gap: 1rem;">&lt;!--[!code highlight]--> &lt;div class="d-flex justify-content-between align-items-center"> &lt;h5 class="mb-0">Peek the neighbors&lt;/h5> &lt;div> &lt;button class="btn-icon btn-sm" type="button" data-bs-target="#carouselPeek" data-bs-slide="prev" style="--bs-carousel-control-icon-width: 1rem;"> &lt;span class="carousel-icon-prev" aria-hidden="true">&lt;/span> &lt;span class="visually-hidden">Previous&lt;/span> &lt;/button> &lt;button class="btn-icon btn-sm" type="button" data-bs-target="#carouselPeek" data-bs-slide="next" style="--bs-carousel-control-icon-width: 1rem;"> &lt;span class="carousel-icon-next" aria-hidden="true">&lt;/span> &lt;span class="visually-hidden">Next&lt;/span> &lt;/button> &lt;/div> &lt;/div> &lt;div class="carousel-inner"> &lt;div class="carousel-item active">&lt;Placeholder width="800" height="300" class="bd-placeholder-img-lg d-block w-100 rounded-5" color="#fff" background="#777" text="First slide" />&lt;/div> &lt;div class="carousel-item">&lt;Placeholder width="800" height="300" class="bd-placeholder-img-lg d-block w-100 rounded-5" color="#fff" background="#666" text="Second slide" />&lt;/div> &lt;div class="carousel-item">&lt;Placeholder width="800" height="300" class="bd-placeholder-img-lg d-block w-100 rounded-5" color="#fff" background="#555" text="Third slide" />&lt;/div> &lt;div class="carousel-item">&lt;Placeholder width="800" height="300" class="bd-placeholder-img-lg d-block w-100 rounded-5" color="#fff" background="#444" text="Fourth slide" />&lt;/div> &lt;div class="carousel-item">&lt;Placeholder width="800" height="300" class="bd-placeholder-img-lg d-block w-100 rounded-5" color="#fff" background="#333" text="Fifth slide" />&lt;/div> &lt;/div> &lt;/div>} />

Variable width

Add .carousel-auto and size each .carousel-item yourself (utilities or custom CSS). Snap points still land on every slide.