With Bootstrap Carousel, you can add a slideshow to your website easily and customize it to match your website’s design. It is a great way to showcase products, portfolio items, or other content in an interactive and eye-catching way. The Bootstrap Carousel is optimized for mobile devices and is easy to use, making it a popular choice for web developers.
<div id="myCarousel" class="carousel slide" data-ride="carousel"> <!-- Indicators --> <ol class="carousel-indicators"> <li data-target="#myCarousel" data-slide-to="0" class="active"></li> <li data-target="#myCarousel" data-slide-to="1"></li> <li data-target="#myCarousel" data-slide-to="2"></li> </ol> <!-- Wrapper for slides --> <div class="carousel-inner"> <div class="carousel-item active"> <img src="slide1.jpg" alt="Slide 1"> <div class="carousel-caption"> <h3>Slide 1 Heading</h3> <p>Slide 1 Description</p> </div> </div> <div class="carousel-item"> <img src="slide2.jpg" alt="Slide 2"> <div class="carousel-caption"> <h3>Slide 2 Heading</h3> <p>Slide 2 Description</p> </div> </div> <div class="carousel-item"> <img src="slide3.jpg" alt="Slide 3"> <div class="carousel-caption"> <h3>Slide 3 Heading</h3> <p>Slide 3 Description</p> </div> </div> </div> <!-- Controls --> <a class="carousel-control-prev" href="#myCarousel" 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="#myCarousel" role="button" data-slide="next"> <span class="carousel-control-next-icon" aria-hidden="true"></span> <span class="sr-only">Next</span> </a> </div>
In the above code, we use id="myCarousel"
to create a Carousel and carousel-item
define each slide for Carousel
.
active class is to make active the slide. By default the first slide is active.
carousel-caption
class used for creating captions in slides.
The controls are created using the carousel-control-prev
and carousel-control-next
classes. The data-slide
attribute is used to specify the direction of the slide.
Use CDN if you want to use CDN CSS, js , and icons in the head of page
<!-- Bootstrap CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"> <!-- jQuery --> <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script> <!-- Popper.js --> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script> <!-- Bootstrap JS --> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
Carousel Benefits
- Attention-grabbing
- Space-saving
- Interactive
- Customizable
- Mobile-friendly
- Easy to implement
Bootstrap Carousel FAQs
What is Bootstrap Carousel?
Bootstrap Carousel is a component that allows you to create a slideshow of images or content
How do I add Bootstrap Carousel to my website?
You can add Bootstrap Carousel to your website by including the necessary CSS and JavaScript files in your HTML code
Can I customize the appearance of my Bootstrap Carousel?
Yes
Is Bootstrap Carousel mobile-friendly?
Yes, Bootstrap Carousel is fully responsive and optimized for mobile devices
Can I add captions or descriptions to my Bootstrap Carousel slides?
Yes, you can add
Can I add navigation controls to my Bootstrap Carousel?
Yes
Is Bootstrap Carousel easy to use?
Yes, Bootstrap Carousel is easy to use