agyanadda@gmail.com

Bootstrap Carousel

Bootstrap Components 1 min read Updated Dec 1, 2026 Topic 20 of 32

A carousel is a slideshow of images or content.

Parts

  • carousel slide — wrapper with an id (add carousel-fade for a fade effect)
  • carousel-indicators — the small dots
  • carousel-inner with several carousel-item (one must be active)
  • carousel-caption — text on the slide
  • carousel-control-prev / -next — arrows

Auto-play

data-bs-ride="carousel" starts sliding automatically. Change the speed per slide with data-bs-interval="3000".

Tips

  • Use images of the same size, with d-block w-100
  • Captions are hidden on phones with d-none d-md-block
  • Do not put very important information only in a slider — many visitors never see slide 2.

Example

Example — Image slider with captions HTML
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">

<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" data-bs-interval="3000">
      <img src="https://picsum.photos/id/1018/1200/400" class="d-block w-100" alt="Mountains">
      <div class="carousel-caption d-none d-md-block"><h5>Learn HTML</h5><p>Start your web journey.</p></div>
    </div>
    <div class="carousel-item" data-bs-interval="3000">
      <img src="https://picsum.photos/id/1043/1200/400" class="d-block w-100" alt="Forest">
      <div class="carousel-caption d-none d-md-block"><h5>Style with CSS</h5><p>Make it beautiful.</p></div>
    </div>
    <div class="carousel-item" data-bs-interval="3000">
      <img src="https://picsum.photos/id/1039/1200/400" class="d-block w-100" alt="Waterfall">
      <div class="carousel-caption d-none d-md-block"><h5>Build with Bootstrap</h5><p>Ship faster.</p></div>
    </div>
  </div>
  <button class="carousel-control-prev" type="button" data-bs-target="#heroSlider" data-bs-slide="prev">
    <span class="carousel-control-prev-icon"></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"></span><span class="visually-hidden">Next</span>
  </button>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>

Test Yourself With Exercises

Exercise 1 Multiple Choice

Which class must one slide have so the carousel shows it first?

Exercise 2 True / False

carousel-fade changes the slide effect to fading.

Exercise 3 Fill in the Blank

data-bs-___="3000" sets a slide to show for 3 seconds.

Frequently Asked Questions

The images have different sizes. Crop them to the same ratio, or give images a fixed height with object-fit-cover.