A carousel is used to display multiple pieces of visual content without taking up too much space. Carousels eliminate the need to scroll down the page to see all content and are a popular method of displaying marketing information.
Default markup
Use a carousel to make your website design more visually appealing for users. In the default carousel design, respective elements slide automatically and users can go to the next slide by clicking an arrow.
<div id= "carousel-sample" class= "carousel slide" data-bs-ride= "carousel" >
<div class= "carousel-indicators" >
<button type= "button" data-bs-target= "#carousel-sample" data-bs-slide-to= "0" class= "active" ></button>
<button type= "button" data-bs-target= "#carousel-sample" data-bs-slide-to= "1" class= "" ></button>
<button type= "button" data-bs-target= "#carousel-sample" data-bs-slide-to= "2" class= "" ></button>
<button type= "button" data-bs-target= "#carousel-sample" data-bs-slide-to= "3" class= "" ></button>
<button type= "button" data-bs-target= "#carousel-sample" data-bs-slide-to= "4" class= "" ></button>
</div>
<div class= "carousel-inner" >
<div class= "carousel-item active" >
<img class= "d-block w-100" alt= "" src= "..." >
</div>
<div class= "carousel-item" >
<img class= "d-block w-100" alt= "" src= "..." >
</div>
<div class= "carousel-item" >
<img class= "d-block w-100" alt= "" src= "..." >
</div>
<div class= "carousel-item" >
<img class= "d-block w-100" alt= "" src= "..." >
</div>
<div class= "carousel-item" >
<img class= "d-block w-100" alt= "" src= "..." >
</div>
</div>
<a class= "carousel-control-prev" href= "#carousel-sample" 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= "#carousel-sample" role= "button" data-bs-slide= "next" >
<span class= "carousel-control-next-icon" aria-hidden= "true" ></span>
<span class= "visually-hidden" > Next</span>
</a>
</div>
Dots indicators
You can replace the standard indicators with dots. Just add the carousel-indicators-dot
class to your carousel:
<div id= "carousel-indicators-dot" class= "carousel slide carousel-fade" data-bs-ride= "carousel" >
<div class= "carousel-indicators carousel-indicators-dot" >
<button type= "button" data-bs-target= "#carousel-indicators-dot" data-bs-slide-to= "0" class= "active" ></button>
<button type= "button" data-bs-target= "#carousel-indicators-dot" data-bs-slide-to= "1" class= "" ></button>
<button type= "button" data-bs-target= "#carousel-indicators-dot" data-bs-slide-to= "2" class= "" ></button>
<button type= "button" data-bs-target= "#carousel-indicators-dot" data-bs-slide-to= "3" class= "" ></button>
<button type= "button" data-bs-target= "#carousel-indicators-dot" data-bs-slide-to= "4" class= "" ></button>
</div>
<div class= "carousel-inner" >
<div class= "carousel-item active" >
<img class= "d-block w-100" alt= "" src= "..." >
</div>
<div class= "carousel-item" >
<img class= "d-block w-100" alt= "" src= "..." >
</div>
<div class= "carousel-item" >
<img class= "d-block w-100" alt= "" src= "..." >
</div>
<div class= "carousel-item" >
<img class= "d-block w-100" alt= "" src= "..." >
</div>
<div class= "carousel-item" >
<img class= "d-block w-100" alt= "" src= "..." >
</div>
</div>
</div>
Thumb indicators
The syntax is similar with thumbnails. Add class carousel-indicators-thumb
and add background-image
to element [data-bs-target]
. Default thumbnails have an aspect ratio of 1:1. To change this use ratio
utils.
<div id= "carousel-indicators-thumb" class= "carousel slide carousel-fade" data-bs-ride= "carousel" >
<div class= "carousel-indicators carousel-indicators-thumb" >
<button type= "button" data-bs-target= "#carousel-indicators-thumb" data-bs-slide-to= "0" class= "ratio ratio-4x3 active" style= "background-image: url(...)" ></button>
<button type= "button" data-bs-target= "#carousel-indicators-thumb" data-bs-slide-to= "1" class= "ratio ratio-4x3" style= "background-image: url(...)" ></button>
<button type= "button" data-bs-target= "#carousel-indicators-thumb" data-bs-slide-to= "2" class= "ratio ratio-4x3" style= "background-image: url(...)" ></button>
<button type= "button" data-bs-target= "#carousel-indicators-thumb" data-bs-slide-to= "3" class= "ratio ratio-4x3" style= "background-image: url(...)" ></button>
<button type= "button" data-bs-target= "#carousel-indicators-thumb" data-bs-slide-to= "4" class= "ratio ratio-4x3" style= "background-image: url(...)" ></button>
</div>
<div class= "carousel-inner" >
<div class= "carousel-item active" >
<img class= "d-block w-100" alt= "" src= "..." >
</div>
<div class= "carousel-item" >
<img class= "d-block w-100" alt= "" src= "..." >
</div>
<div class= "carousel-item" >
<img class= "d-block w-100" alt= "" src= "..." >
</div>
<div class= "carousel-item" >
<img class= "d-block w-100" alt= "" src= "..." >
</div>
<div class= "carousel-item" >
<img class= "d-block w-100" alt= "" src= "..." >
</div>
</div>
</div>
Vertical indicators
To make the indicators go to the right side, add the carousel-indicators-vertical
class. You can combine it with other classes that are responsible for dots or thumbnails.
<div id= "carousel-indicators-dot-vertical" class= "carousel slide carousel-fade" data-bs-ride= "carousel" >
<div class= "carousel-indicators carousel-indicators-vertical carousel-indicators-dot" >
<button type= "button" data-bs-target= "#carousel-indicators-dot-vertical" data-bs-slide-to= "0" class= "active" ></button>
<button type= "button" data-bs-target= "#carousel-indicators-dot-vertical" data-bs-slide-to= "1" class= "" ></button>
<button type= "button" data-bs-target= "#carousel-indicators-dot-vertical" data-bs-slide-to= "2" class= "" ></button>
<button type= "button" data-bs-target= "#carousel-indicators-dot-vertical" data-bs-slide-to= "3" class= "" ></button>
<button type= "button" data-bs-target= "#carousel-indicators-dot-vertical" data-bs-slide-to= "4" class= "" ></button>
</div>
<div class= "carousel-inner" >
<div class= "carousel-item active" >
<img class= "d-block w-100" alt= "" src= "..." >
</div>
<div class= "carousel-item" >
<img class= "d-block w-100" alt= "" src= "..." >
</div>
<div class= "carousel-item" >
<img class= "d-block w-100" alt= "" src= "..." >
</div>
<div class= "carousel-item" >
<img class= "d-block w-100" alt= "" src= "..." >
</div>
<div class= "carousel-item" >
<img class= "d-block w-100" alt= "" src= "..." >
</div>
</div>
</div>
Likewise, you can add thumbnails on the right side:
<div id= "carousel-indicators-thumb-vertical" class= "carousel slide carousel-fade" data-bs-ride= "carousel" >
<div class= "carousel-indicators carousel-indicators-vertical carousel-indicators-thumb" >
<button type= "button" data-bs-target= "#carousel-indicators-thumb-vertical" data-bs-slide-to= "0" class= "ratio ratio-4x3 active" style= "background-image: url(...)" ></button>
<button type= "button" data-bs-target= "#carousel-indicators-thumb-vertical" data-bs-slide-to= "1" class= "ratio ratio-4x3" style= "background-image: url(...)" ></button>
<button type= "button" data-bs-target= "#carousel-indicators-thumb-vertical" data-bs-slide-to= "2" class= "ratio ratio-4x3" style= "background-image: url(...)" ></button>
<button type= "button" data-bs-target= "#carousel-indicators-thumb-vertical" data-bs-slide-to= "3" class= "ratio ratio-4x3" style= "background-image: url(...)" ></button>
<button type= "button" data-bs-target= "#carousel-indicators-thumb-vertical" data-bs-slide-to= "4" class= "ratio ratio-4x3" style= "background-image: url(...)" ></button>
</div>
<div class= "carousel-inner" >
<div class= "carousel-item active" >
<img class= "d-block w-100" alt= "" src= "..." >
</div>
<div class= "carousel-item" >
<img class= "d-block w-100" alt= "" src= "..." >
</div>
<div class= "carousel-item" >
<img class= "d-block w-100" alt= "" src= "..." >
</div>
<div class= "carousel-item" >
<img class= "d-block w-100" alt= "" src= "..." >
</div>
<div class= "carousel-item" >
<img class= "d-block w-100" alt= "" src= "..." >
</div>
</div>
</div>
Carousel with captions
Add captions to your slides easily with the .carousel-caption
element within any .carousel-item
. To make the text more readable on the image you can add carousel-caption-background
which will add a black overlay over the image.
Slide label
Nulla vitae elit libero, a pharetra augue mollis interdum.
Slide label
Nulla vitae elit libero, a pharetra augue mollis interdum.
Slide label
Nulla vitae elit libero, a pharetra augue mollis interdum.
Slide label
Nulla vitae elit libero, a pharetra augue mollis interdum.
Slide label
Nulla vitae elit libero, a pharetra augue mollis interdum.
Previous
Next
<div id= "carousel-captions" class= "carousel slide" data-bs-ride= "carousel" >
<div class= "carousel-inner" >
<div class= "carousel-item active" >
<img class= "d-block w-100" alt= "" src= "..." >
<div class= "carousel-caption-background d-none d-md-block" ></div>
<div class= "carousel-caption d-none d-md-block" >
<h3> Slide label</h3>
<p> Nulla vitae elit libero, a pharetra augue mollis interdum.</p>
</div>
</div>
<div class= "carousel-item" >
<img class= "d-block w-100" alt= "" src= "..." >
<div class= "carousel-caption-background d-none d-md-block" ></div>
<div class= "carousel-caption d-none d-md-block" >
<h3> Slide label</h3>
<p> Nulla vitae elit libero, a pharetra augue mollis interdum.</p>
</div>
</div>
<div class= "carousel-item" >
<img class= "d-block w-100" alt= "" src= "..." >
<div class= "carousel-caption-background d-none d-md-block" ></div>
<div class= "carousel-caption d-none d-md-block" >
<h3> Slide label</h3>
<p> Nulla vitae elit libero, a pharetra augue mollis interdum.</p>
</div>
</div>
<div class= "carousel-item" >
<img class= "d-block w-100" alt= "" src= "..." >
<div class= "carousel-caption-background d-none d-md-block" ></div>
<div class= "carousel-caption d-none d-md-block" >
<h3> Slide label</h3>
<p> Nulla vitae elit libero, a pharetra augue mollis interdum.</p>
</div>
</div>
<div class= "carousel-item" >
<img class= "d-block w-100" alt= "" src= "..." >
<div class= "carousel-caption-background d-none d-md-block" ></div>
<div class= "carousel-caption d-none d-md-block" >
<h3> Slide label</h3>
<p> Nulla vitae elit libero, a pharetra augue mollis interdum.</p>
</div>
</div>
</div>
<a class= "carousel-control-prev" href= "#carousel-captions" 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= "#carousel-captions" role= "button" data-bs-slide= "next" >
<span class= "carousel-control-next-icon" aria-hidden= "true" ></span>
<span class= "visually-hidden" > Next</span>
</a>
</div>