Carousel: Image Slider

Bootstrap Framework 10 min min read Updated: Nov 16, 2026 Intermediate
Carousel: Image Slider
Intermediate Topic 11 of 14

What is a Carousel?

A carousel is a slideshow that cycles through images or content. It is often used for hero banners, featured products and testimonials.

Complete Carousel

html <div id="heroSlider" class="carousel slide" data-bs-ride="carousel"> <div class="carousel-indicators"> <button type="button" data-bs-target="#heroSlider" data-bs-slide-to="0" class="active" aria-label="Slide 1"></button> <button type="button" data-bs-target="#heroSlider" data-bs-slide-to="1" aria-label="Slide 2"></button> <button type="button" data-bs-target="#heroSlider" data-bs-slide-to="2" aria-label="Slide 3"></button> </div> <div class="carousel-inner"> <div class="carousel-item active"> <img src="slide1.jpg" class="d-block w-100" alt="First slide"> <div class="carousel-caption d-none d-md-block"> <h5>First Slide</h5> <p>Caption for the first slide.</p> </div> </div> <div class="carousel-item"> <img src="slide2.jpg" class="d-block w-100" alt="Second slide"> </div> <div class="carousel-item"> <img src="slide3.jpg" class="d-block w-100" alt="Third slide"> </div> </div> <button class="carousel-control-prev" type="button" data-bs-target="#heroSlider" data-bs-slide="prev"> <span class="carousel-control-prev-icon" aria-hidden="true"></span> <span class="visually-hidden">Previous</span> </button> <button class="carousel-control-next" type="button" data-bs-target="#heroSlider" data-bs-slide="next"> <span class="carousel-control-next-icon" aria-hidden="true"></span> <span class="visually-hidden">Next</span> </button> </div>

Main Parts

PartPurpose
carousel slideThe main wrapper with sliding animation
data-bs-ride="carousel"Starts the auto play on page load
carousel-innerHolds all slides
carousel-itemOne slide. Exactly one needs active
carousel-indicatorsSmall dots at the bottom
carousel-control-prev / nextArrow buttons
carousel-captionText over the slide
Common bug: If no slide has the active class, nothing will be shown. Give the first carousel-item the class active.

Options

  • carousel-fade on the wrapper changes the slide effect to a fade
  • data-bs-interval="3000" on a slide sets how long it stays (milliseconds)
  • data-bs-pause="hover" pauses when the mouse is on the slider
  • data-bs-ride="true" starts after the first interaction instead of automatically

Carousel with Only Controls

Remove the carousel-indicators block and the data-bs-ride attribute if you want a manual slider only.

Making Images the Same Size

html <img src="slide1.jpg" class="d-block w-100 object-fit-cover" style="height: 400px;" alt="Slide">
Performance tip: Compress your slider images (WebP or optimized JPG) and avoid too many slides. Large images slow down your page.
Result

A slider that moves automatically every few seconds, with dots, arrows and a caption on the first slide.

Conclusion

A carousel brings your page to life, but use it wisely. Fewer, high-quality slides are better than many.

Quick Summary: carousel slide, carousel-inner with carousel-item (one active), indicators and prev/next controls with matching ids.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators