In Bootstrap 5, the Carousel component is used to create a slideshow of images or content that can be automatically or manually advanced. The Carousel component provides a visually appealing way to showcase multiple items in a rotating manner. Here's an example of how to create a basic carousel in Bootstrap 5:
html
<div id="myCarousel" class="carousel slide" data-bs-ride="carousel">
<ol class="carousel-indicators">
<li data-bs-target="#myCarousel" data-bs-slide-to="0" class="active"></li>
<li data-bs-target="#myCarousel" data-bs-slide-to="1"></li>
<li data-bs-target="#myCarousel" data-bs-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<img src="image1.jpg" class="d-block w-100" alt="Image 1">
</div>
<div class="carousel-item">
<img src="image2.jpg" class="d-block w-100" alt="Image 2">
</div>
<div class="carousel-item">
<img src="image3.jpg" class="d-block w-100" alt="Image 3">
</div>
</div>
<a class="carousel-control-prev" href="#myCarousel" role="button" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</a>
<a class="carousel-control-next" href="#myCarousel" role="button" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</a>
</div>
In this example, we have a carousel component with the id `myCarousel`. The carousel indicators are represented by the `<ol>` element with the class `carousel-indicators`. Each indicator is defined by an `<li>` element with the `data-bs-target` attribute pointing to the carousel id and the `data-bs-slide-to` attribute indicating the slide index. The first indicator is marked as active using the `active` class.
The actual carousel items are placed within the `<div>` element with the class `carousel-inner`. Each item is represented by a `<div>` element with the class `carousel-item`. The first item is marked as active using the `active` class. Inside each item, you can include content such as images, text, or other elements.
The previous and next controls are created using the `<a>` elements with the classes `carousel-control-prev` and `carousel-control-next`. The `href` attribute points to the carousel id, and the `data-bs-slide` attribute specifies the slide direction.
Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.
We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc