Bootstrap Carousel Example on CodePen

Ruth Jul 09, 2026

Bootstrap, a popular front-end framework, offers a wide range of components to simplify and enhance web development. One of its standout features is the carousel, a versatile tool for creating slideshows or rotating banners. Let's delve into an example of Bootstrap carousel using CodePen, a web development platform that allows you to create, test, and share HTML, CSS, and JavaScript snippets.

CSS Carousels
CSS Carousels

Before we dive into the CodePen example, let's briefly understand what a Bootstrap carousel is and why it's useful. A carousel is a slideshow component that cycles through a series of content, such as images, text, or even interactive elements. It's highly customizable and responsive, making it an excellent choice for displaying multiple pieces of information in a limited space.

Create a carousel out of nothing but CSS
Create a carousel out of nothing but CSS

Setting Up the Bootstrap Carousel

The first step in creating a Bootstrap carousel is to include the necessary CSS and JavaScript files. You can either download and host these files locally or use the CDN (Content Delivery Network) links provided by Bootstrap's official website.

CSS Carousels with Hover Effect
CSS Carousels with Hover Effect

Once the files are included, you can start building your carousel. The basic structure involves a wrapper div with the class 'carousel', and inside it, two more divs with classes 'carousel-inner' and 'carousel-item' for each slide.

Basic Carousel Structure

Slick – jQuery Responsive Touch Carousel
Slick – jQuery Responsive Touch Carousel

Here's a simple example of a Bootstrap carousel structure:

<div class="carousel" id="myCarousel"> <div class="carousel-inner"> <div class="carousel-item active"> <img src="..." alt="First slide"> </div> <div class="carousel-item"> <img src="..." alt="Second slide"> </div> <div class="carousel-item"> <img src="..." alt="Third slide"> </div> </div> <button class="carousel-control-prev"> <span class="carousel-control-prev-icon"></span> </button> <button class="carousel-control-next"> <span class="carousel-control-next-icon"></span> </button> </div>

The 'active' class is used to indicate which slide is currently visible. The 'carousel-control-prev' and 'carousel-control-next' buttons are used to navigate through the slides.

Adding JavaScript

3D Carousel in CSS
3D Carousel in CSS

To make the carousel functional, you need to add some JavaScript. Bootstrap provides a jQuery plugin that initializes and manages the carousel. Here's how you can use it:

<script> $(document).ready(function(){ $('#myCarousel').carousel(); }); </script>

In this example, we're using jQuery to select the carousel with the id 'myCarousel' and initialize it using the carousel() function.

Customizing the Carousel

an image of a sailboat with the caption'what we offer '
an image of a sailboat with the caption'what we offer '

Bootstrap carousels are highly customizable. You can change the interval between slides, add captions, or even create multi-item carousels. Let's explore a few customization options.

Adding Captions

15+ Best Free React JS carousel / Slider to use
15+ Best Free React JS carousel / Slider to use
Carousel (React)
Carousel (React)
Carousel designs
Carousel designs
Bootstrap Carousel Multiple Items
Bootstrap Carousel Multiple Items
Carousel Slider Using Bootstrap 5 Alpha - Carousel Slider Tutorial
Carousel Slider Using Bootstrap 5 Alpha - Carousel Slider Tutorial
Scrolling Bootstrap Card Carousel
Scrolling Bootstrap Card Carousel
a set of four different blue and white business brochure templates with arrows
a set of four different blue and white business brochure templates with arrows
Instagram/LinkedIn Carousel | Canva Template
Instagram/LinkedIn Carousel | Canva Template
CSS Carousels
CSS Carousels
Postingan IG carousel BEM FKD
Postingan IG carousel BEM FKD
Bootstrap 5 Testimonial Slider
Bootstrap 5 Testimonial Slider
Partner logo as Carousel
Partner logo as Carousel
Multiple Post Carousel Design
Multiple Post Carousel Design
Parallax Photo Carousel using HTML CSS JS
Parallax Photo Carousel using HTML CSS JS
Carousel Design
Carousel Design
a computer screen with the words how to split a seamless carousel in canva?
a computer screen with the words how to split a seamless carousel in canva?
Create Any Carousel in Figma (Beginner Tutorial)
Create Any Carousel in Figma (Beginner Tutorial)
#CSS Animations Tips and Tricks
#CSS Animations Tips and Tricks
CAROUSEL FEED 5 SLIDE 20 FOTO
CAROUSEL FEED 5 SLIDE 20 FOTO
Seamless Canva Carousels for Social Media Success | Coach & Business Growth Instagram Template
Seamless Canva Carousels for Social Media Success | Coach & Business Growth Instagram Template

To add captions to your slides, you can use the 'carousel-caption' class. Here's how you can do it:

<div class="carousel-item active"> <img src="..." alt="First slide"> <div class="carousel-caption d-none d-md-block"> <h5>First slide label</h5> <p>Nulla vitae elit libero, a pharetra augue mollis interdum.</p> </div> </div>

The 'd-none d-md-block' classes are used to hide the caption on small devices and show it on medium and larger devices.

Creating a Multi-Item Carousel

By default, Bootstrap carousels display one item at a time. However, you can create a multi-item carousel by adding the 'carousel-item' class to multiple child elements within the 'carousel-inner' div. Here's an example:

<div class="carousel-item active"> <img src="..." alt="First slide"> </div> <div class="carousel-item"> <img src="..." alt="Second slide"> </div> <div class="carousel-item"> <img src="..." alt="Third slide"> </div> <div class="carousel-item"> <img src="..." alt="Fourth slide"> </div>

In this example, the carousel will display four items at a time.

Now that we've explored the basics of Bootstrap carousels, let's see how we can use CodePen to create and test our carousels. CodePen is a web-based code editor that allows you to write HTML, CSS, and JavaScript in separate panels. It also provides a live preview of your code, making it an excellent tool for testing and sharing your Bootstrap carousels.

To create a Bootstrap carousel on CodePen, simply write your HTML, CSS, and JavaScript in the respective panels. You can use the 'Pen Settings' to include the Bootstrap CDN links. Once you've written your code, you can preview it in the live preview pane. CodePen also allows you to share your pens, making it easy to showcase your work or get feedback from others.

In conclusion, Bootstrap carousels are powerful tools for creating engaging and responsive slideshows. With a little bit of HTML, CSS, and JavaScript, you can create custom carousels that enhance the user experience on your website. Whether you're using CodePen or another development environment, Bootstrap carousels are a versatile and user-friendly way to display multiple pieces of information in a limited space. So, start exploring and creating your own Bootstrap carousels today!