Carousel: Image Slider
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
| Part | Purpose |
|---|---|
carousel slide | The main wrapper with sliding animation |
data-bs-ride="carousel" | Starts the auto play on page load |
carousel-inner | Holds all slides |
carousel-item | One slide. Exactly one needs active |
carousel-indicators | Small dots at the bottom |
carousel-control-prev / next | Arrow buttons |
carousel-caption | Text 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-fadeon the wrapper changes the slide effect to a fadedata-bs-interval="3000"on a slide sets how long it stays (milliseconds)data-bs-pause="hover"pauses when the mouse is on the sliderdata-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.

