A slideshow component for cycling through elements—images or slides of text—like a carousel.
Bootstrap 4 documentationThe carousel is a slideshow for cycling through a series of content, built with CSS 3D transforms and a bit of JavaScript. It works with a series of images, text, or custom markup. It also includes support for previous/next controls and indicators.
In browsers where the Page Visibility API is supported, the carousel will avoid sliding when the webpage is not visible to the user (such as when the browser tab is inactive, the browser window is minimized, etc.).
For more detailed information and examples, see the official bootstrap documentation: Bootstrap carousel.
Here’s a carousel with slides only. Note the presence of the .d-block
and .w-100
on carousel images to prevent browser default image alignment.
<!-- Carousel -->
<div id="Carousel1" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img src="../../assets/img/carousel/image-1.jpg" class="d-block w-100" alt="slide1">
</div>
<div class="carousel-item">
<img src="../../assets/img/carousel/image-2.jpg" class="d-block w-100" alt="slide2">
</div>
<div class="carousel-item">
<img src="../../assets/img/carousel/image-3.jpg" class="d-block w-100" alt="slide3">
</div>
</div>
</div>
<!-- End of Carousel -->
Adding in the previous and next controls:
<!-- Carousel -->
<div id="Carousel2" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img class="d-block w-100" src="../../assets/img/carousel/image-1.jpg" alt="First slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="../../assets/img/carousel/image-2.jpg" alt="Second slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="../../assets/img/carousel/image-3.jpg" alt="Third slide">
</div>
</div>
<a class="carousel-control-prev" href="#Carousel2" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#Carousel2" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<!-- End of Carousel -->
You can also add the indicators to the carousel, alongside the controls, too.
<!-- Carousel -->
<div id="Carousel3" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#Carousel3" data-slide-to="0" class="active"></li>
<li data-target="#Carousel3" data-slide-to="1"></li>
<li data-target="#Carousel3" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<img class="d-block w-100" src="../../assets/img/carousel/image-1.jpg" alt="First slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="../../assets/img/carousel/image-2.jpg" alt="Second slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="../../assets/img/carousel/image-3.jpg" alt="Third slide">
</div>
</div>
<a class="carousel-control-prev" href="#Carousel3" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#Carousel3" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<!-- End of Carousel -->