Bootstrap5 Carousel
A carousel is a looping slideshow:
How to Create a Carousel
The following example creates a simple image carousel effect:
Example
<div id="demo" class=">carousel slide
"
data-bs-ride
=
"
carousel
"
<div class="carousel-indicators">
<button type="button" data-bs-target="#demo" data-bs-slide-to="0" class="active" button>
<button type="button" data-bs-target="#demo" data-bs-slide-to="1" button>
<button type="button" data-bs-target="#demo" data-bs-slide-to="2" button div>
<div class="carousel-inner">
<div class=">carousel-item active
"
<img src="https://static.jyshare.com/images/mix/img_fjords_wide.jpg" class="d-block" style="width:100%" div>
<div class="carousel-item">
<img src="https://static.jyshare.com/images/mix/img_nature_wide.jpg" class="d-block" style="width:100%" div>
<div class="carousel-item">
<img src="https://static.jyshare.com/images/mix/img_mountains_wide.jpg" class="d-block" style="width:100%" div div>
<button class="carousel-control-prev" type="button" data-bs-target="#demo" data-bs-slide="prev">
<span class="carousel-control-prev-icon" span button>
<button class="carousel-control-next" type="button" data-bs-target="#demo" data-bs-slide="next">
<span class="carousel-control-next-icon" span button div>Try it »
Adding Captions to Carousel Images
Insert content after each
add a
to set the caption text for carousel images::
Example
<div class="carousel-item">
<img src="https://static.jyshare.com/images/mix/img_fjords_wide.jpg" class="d-block" style="width:100%">
<div class="carousel-caption">
<h3>First Image Caption Title
h3
<
p
The description content of the first image is shown here!!!
p
div
div
Try it »
Descriptions of the Classes Used in the Above Example
| class | Description |
|---|---|
.carousel |
Create a carousel |
.carousel-indicators |
Add an indicator to the carousel, the small dots below the carousel images, which show which slide is currently displayed during the carousel. |
.carousel-inner |
Add the images to switch between |
.carousel-item |
Specify the content of each image |
.carousel-control-prev |
Add the left button, clicking it returns to the previous slide. |
.carousel-control-next |
Add the right button, clicking it switches to the next slide. |
.carousel-control-prev-icon |
Used with .carousel-control-prev to set the left button |
.carousel-control-next-icon |
Used with .carousel-control-next to set the right button |
.slide |
The transition and animation effects when switching images; if you don't need such effects, you can remove this class. |