Carousel

Bootstrap Carousel

Note: This documentation is for an older version of Bootstrap (v.4). A newer version is available for Bootstrap 5. We recommend migrating to the latest version of our product - Material Design for Bootstrap 5.
Go to docs v.5

A slideshow component for cycling through elements—images or slides of text—like a carousel.


How it works

The carousel is a slideshow for cycling through a series of content, built with CSS 3D transforms and a bit of JavaScript. It works with a series of images, text, or custom markups. It also includes support for previous/next controls and indicators.

In browsers where the Page Visibility API is supported, the carousel will avoid sliding when the webpage is not visible to the user (such as when the browser tab is inactive, the browser window is minimized, etc.).

Please be aware that nested carousels are not supported, and carousels are generally not compliant with accessibility standards.


Example

Carousels don’t automatically normalize slide dimensions. As such, you may need to use additional utilities or custom styles to appropriately size content. While carousels support previous/next controls and indicators, they’re not explicitly required. So you may add and customize them as you see fit.

The .active class needs to be added to one of the slides otherwise the .carousel will not be visible. Also be sure to set a unique id on the .carousel for optional controls, especially if you’re using multiple carousels on a single page. Control and indicator elements must have a data-target attribute (or href for links) that matches the id of the carousel element.

Slides only

Here’s a carousel with slides only. Note the presence of the .d-block and .w-100 on carousel images to prevent browser default image alignment.

        
            

        <div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel">
          <div class="carousel-inner">
            <div class="carousel-item active">
              <img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(35).webp">
            </div>
            <div class="carousel-item">
              <img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(33).webp">
            </div>
            <div class="carousel-item">
              <img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(31).webp">
            </div>
          </div>
        </div>

      
        
    

With controls

Adding in the previous and next controls:

        
            

        <div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
          <div class="carousel-inner">
            <div class="carousel-item active">
              <img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(45).webp"
                alt="First slide">
            </div>
            <div class="carousel-item">
              <img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(46).webp"
                alt="Second slide">
            </div>
            <div class="carousel-item">
              <img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(47).webp"
                alt="Third slide">
            </div>
          </div>
          <a class="carousel-control-prev" href="#carouselExampleControls" 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="#carouselExampleControls" role="button" data-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="sr-only">Next</span>
          </a>
        </div>
      
        
    

With indicators

You can also add indicators to the carousel, alongside its controls, too.

        
            
        <!--Carousel Wrapper-->
        <div id="carousel-example-1z" class="carousel slide carousel-fade" data-ride="carousel">
          <!--Indicators-->
          <ol class="carousel-indicators">
            <li data-target="#carousel-example-1z" data-slide-to="0" class="active"></li>
            <li data-target="#carousel-example-1z" data-slide-to="1"></li>
            <li data-target="#carousel-example-1z" data-slide-to="2"></li>
          </ol>
          <!--/.Indicators-->
          <!--Slides-->
          <div class="carousel-inner" role="listbox">
            <!--First slide-->
            <div class="carousel-item active">
              <img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(130).webp"
                alt="First slide">
            </div>
            <!--/First slide-->
            <!--Second slide-->
            <div class="carousel-item">
              <img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(129).webp"
                alt="Second slide">
            </div>
            <!--/Second slide-->
            <!--Third slide-->
            <div class="carousel-item">
              <img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(70).webp"
                alt="Third slide">
            </div>
            <!--/Third slide-->
          </div>
          <!--/.Slides-->
          <!--Controls-->
          <a class="carousel-control-prev" href="#carousel-example-1z" 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="#carousel-example-1z" role="button" data-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="sr-only">Next</span>
          </a>
          <!--/.Controls-->
        </div>
        <!--/.Carousel Wrapper-->
      
        
    

With captions

Add captions to your slides easily with the .carousel-caption element within any .carousel-item. They can be easily hidden on smaller viewports, as shown below, with optional display utilities. We hide them initially with .d-none and bring them back on medium-sized devices with .d-md-block.

If your content is not visible enough, you can cover the image with a darker mask.

You can easily change the intensity and color of the mask. To learn more read our MASKS documentation.

        
            
      <!--Carousel Wrapper-->
        <div id="carousel-example-2" class="carousel slide carousel-fade" data-ride="carousel">
          <!--Indicators-->
          <ol class="carousel-indicators">
            <li data-target="#carousel-example-2" data-slide-to="0" class="active"></li>
            <li data-target="#carousel-example-2" data-slide-to="1"></li>
            <li data-target="#carousel-example-2" data-slide-to="2"></li>
          </ol>
          <!--/.Indicators-->
          <!--Slides-->
          <div class="carousel-inner" role="listbox">
            <div class="carousel-item active">
              <div class="view">
                <img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(68).webp"
                  alt="First slide">
                <div class="mask rgba-black-light"></div>
              </div>
              <div class="carousel-caption">
                <h3 class="h3-responsive">Light mask</h3>
                <p>First text</p>
              </div>
            </div>
            <div class="carousel-item">
              <!--Mask color-->
              <div class="view">
                <img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(6).webp"
                  alt="Second slide">
                <div class="mask rgba-black-strong"></div>
              </div>
              <div class="carousel-caption">
                <h3 class="h3-responsive">Strong mask</h3>
                <p>Secondary text</p>
              </div>
            </div>
            <div class="carousel-item">
              <!--Mask color-->
              <div class="view">
                <img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(9).webp"
                  alt="Third slide">
                <div class="mask rgba-black-slight"></div>
              </div>
              <div class="carousel-caption">
                <h3 class="h3-responsive">Slight mask</h3>
                <p>Third text</p>
              </div>
            </div>
          </div>
          <!--/.Slides-->
          <!--Controls-->
          <a class="carousel-control-prev" href="#carousel-example-2" 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="#carousel-example-2" role="button" data-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="sr-only">Next</span>
          </a>
          <!--/.Controls-->
        </div>
        <!--/.Carousel Wrapper-->
      
        
    

Crossfade

Add .carousel-fade to your carousel to animate slides with a fade transition instead of a slide.

        
            
      <div id="carouselExampleFade" class="carousel slide carousel-fade" data-ride="carousel">
        <div class="carousel-inner">
          <div class="carousel-item active">
              <img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(15).webp"
                alt="First slide">
            </div>
            <div class="carousel-item">
              <img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(16).webp"
                alt="Second slide">
            </div>
            <div class="carousel-item">
              <img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(17).webp"
                alt="Third slide">
            </div>
          </div>
          <a class="carousel-control-prev" href="#carouselExampleFade" 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="#carouselExampleFade" role="button" data-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="sr-only">Next</span>
          </a>
        </div>
      
        
    





Video carousel

Replace img elements with video elements to create a video carousel.

        
            

        <!--Carousel Wrapper-->
        <div id="video-carousel-example" class="carousel slide carousel-fade" data-ride="carousel">
            <!--Indicators-->
            <ol class="carousel-indicators">
              <li data-target="#video-carousel-example" data-slide-to="0" class="active"></li>
              <li data-target="#video-carousel-example" data-slide-to="1"></li>
              <li data-target="#video-carousel-example" data-slide-to="2"></li>
            </ol>
            <!--/.Indicators-->
            <!--Slides-->
            <div class="carousel-inner" role="listbox">
              <div class="carousel-item active">
                <video class="video-fluid" autoplay loop muted>
                  <source src="https://mdbootstrap.com/img/video/Tropical.mp4" type="video/mp4" />
                </video>
              </div>
              <div class="carousel-item">
                <video class="video-fluid" autoplay loop muted>
                  <source src="https://mdbootstrap.com/img/video/forest.mp4" type="video/mp4" />
                </video>
              </div>
              <div class="carousel-item">
                <video class="video-fluid" autoplay loop muted>
                  <source src="https://mdbootstrap.com/img/video/Agua-natural.mp4" type="video/mp4" />
                </video>
              </div>
            </div>
            <!--/.Slides-->
            <!--Controls-->
            <a class="carousel-control-prev" href="#video-carousel-example" 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="#video-carousel-example" role="button" data-slide="next">
              <span class="carousel-control-next-icon" aria-hidden="true"></span>
              <span class="sr-only">Next</span>
            </a>
            <!--/.Controls-->
          </div>
          <!--Carousel Wrapper-->

        
        
    

Caption and mask

If you want to add a caption to your carousel you will probably also need to cover it with a dark mask to make your caption more visible.

You can easily change the intensity and color of the mask. To learn more read our MASKS documentation.

        
            


          <!--Carousel Wrapper-->
          <div id="video-carousel-example2" class="carousel slide carousel-fade" data-ride="carousel">
            <!--Indicators-->
            <ol class="carousel-indicators">
              <li data-target="#video-carousel-example2" data-slide-to="0" class="active"></li>
              <li data-target="#video-carousel-example2" data-slide-to="1"></li>
              <li data-target="#video-carousel-example2" data-slide-to="2"></li>
            </ol>
            <!--/.Indicators-->
            <!--Slides-->
            <div class="carousel-inner" role="listbox">
              <!-- First slide -->
              <div class="carousel-item active">
                <!--Mask color-->
                <div class="view">
                  <!--Video source-->
                  <video class="video-fluid" autoplay loop muted>
                    <source src="https://mdbootstrap.com/img/video/Lines.mp4" type="video/mp4" />
                  </video>
                  <div class="mask rgba-indigo-light"></div>
                </div>

                <!--Caption-->
                <div class="carousel-caption">
                  <div class="animated fadeInDown">
                    <h3 class="h3-responsive">Light mask</h3>
                    <p>First text</p>
                  </div>
                </div>
                <!--Caption-->
              </div>
              <!-- /.First slide -->

              <!-- Second slide -->
              <div class="carousel-item">
                <!--Mask color-->
                <div class="view">
                  <!--Video source-->
                  <video class="video-fluid" autoplay loop muted>
                    <source src="https://mdbootstrap.com/img/video/animation-intro.mp4" type="video/mp4" />
                  </video>
                  <div class="mask rgba-purple-slight"></div>
                </div>

                <!--Caption-->
                <div class="carousel-caption">
                  <div class="animated fadeInDown">
                    <h3 class="h3-responsive">Super light mask</h3>
                    <p>Secondary text</p>
                  </div>
                </div>
                <!--Caption-->
              </div>
              <!-- /.Second slide -->

              <!-- Third slide -->
              <div class="carousel-item">
                <!--Mask color-->
                <div class="view">
                  <!--Video source-->
                  <video class="video-fluid" autoplay loop muted>
                    <source src="https://mdbootstrap.com/img/video/Tropical.mp4" type="video/mp4" />
                  </video>
                  <div class="mask rgba-black-strong"></div>
                </div>

                <!--Caption-->
                <div class="carousel-caption">
                  <div class="animated fadeInDown">
                    <h3 class="h3-responsive">Strong mask</h3>
                    <p>Third text</p>
                  </div>
                </div>
                <!--Caption-->
              </div>
              <!-- /.Third slide -->
            </div>
            <!--/.Slides-->
            <!--Controls-->
            <a class="carousel-control-prev" href="#video-carousel-example2" 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="#video-carousel-example2" role="button" data-slide="next">
              <span class="carousel-control-next-icon" aria-hidden="true"></span>
              <span class="sr-only">Next</span>
            </a>
            <!--/.Controls-->
          </div>
          <!--Carousel Wrapper-->

        
        
    

Full page carousels

Click the buttons below to see a live preview.

Full Image Carousel Full Video Carousel

Usage

Via data attributes

You can use data attributes to easily control the position of the carousel. data-slide accepts the keywords prev or next, these keyworks alter the slide position relative to its current position. Alternatively, use data-slide-to to pass a raw slide index to the carousel, e.g. data-slide-to="2", that shifts the slide position to a particular index beginning with 0.

The data-ride="carousel" attribute is used to mark a carousel as animating at page load. It cannot be used in combination with a (redundant and unnecessary) explicit JavaScript initialization of the same carousel.


Via JavaScript

Callstarting the carousel manually with the code below.

        
            
          $('.carousel').carousel()
        
        
    

Options

Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-, as in data-interval="".

Name Type Default Description
interval number 5000 The amount of time to delay between automatically cycling an item. If false, the carousel will not automatically cycle.
pause string | boolean "hover"

If set to "hover", pauses the cycling of the carousel on mouseenter and resumes the cycling of the carousel on mouseleave. If set to false, hovering over the carousel won't pause it.

On touch-enabled devices, when set to "hover", cycling will pause on touchend (once the user finished interacting with the carousel) for two intervals, before automatically resuming. Note that this is in addition to the above mouse behavior.

wrap boolean true Whether the carousel should cycle continuously or have hard stops.
ride string false Autoplays the carousel after the user manually cycles the first item. If "carousel", it autoplays the carousel on load.
keyboard boolean true Whether the carousel should react to keyboard events.
touch boolean true Whether the carousel should support left/right swipe interactions on touchscreen devices.

Methods

Asynchronous methods and transitions

All API methods are asynchronous and start a transition. They return to the caller as soon as the transition is started but before it ends. In addition, a method call on a transitioning component will be ignored.

.carousel(options)

Initializes the carousel with an optional options object and starts cycling through items.

        
            
          $('.carousel').carousel({
          interval: 2000
          })
        
        
    
.carousel('cycle')

Cycles through the carousel items from left to right.

.carousel('pause')

Stops the carousel from cycling through items.

.carousel(number)

Cycles the carousel to a particular frame (0 based, similar to an array).

.carousel('prev')

Cycles to the previous item.

.carousel('next')

Cycles to the next item.

.carousel('dispose')

Destroys an element’s carousel.


Events

Bootstrap’s carousel class exposes two events for hooking into carousel functionality. Both of these events have the following additional properties:

  1. direction: The direction in which the carousel is sliding (either "left" or "right").
  2. relatedTarget: The DOM element that is being slid into place as the active item.
  3. from: The index of the current item.
  4. to: The index of the next item.

All carousel events are fired at the carousel itself (i.e. at the <div class="carousel">).

Event Type Description
slide.bs.carousel This event fires immediately when the slide instance method is invoked.
slid.bs.carousel This event is fired when the carousel has completed its slide transition.
        
            
          $('#myCarousel').on('slide.bs.carousel', function () {
          // do something…
          })
        
        
    

Change transition duration

The transition duration of .carousel-item can be changed with the $carousel-transition Sass variable before compiling (or custom styles if you’re using compiled CSS). If multiple transitions are applied, make sure the transform transition is defined first (eg. transition: transform 2s ease, opacity .5s ease-out ).


Carousel with gestures support

Mobile - Material Design for Bootstrap

The Bootstrap allows to use touch support. It is setting to true by default.

More about gestures you can read in our mobile gestures documentation.

Click on the button below to launch a live example and see the Carousel with a gestures support in action.

Live preview
        
            

      <div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel">
        <div class="carousel-inner">
          <div class="carousel-item active">
            <img class="w-100 d-block" src="https://mdbootstrap.com/img/Photos/Slides/img%20(35).webp">
          </div>
          <div class="carousel-item">
            <img class="w-100 d-block" src="https://mdbootstrap.com/img/Photos/Slides/img%20(33).webp">
          </div>
          <div class="carousel-item">
            <img class="w-100 d-block" src="https://mdbootstrap.com/img/Photos/Slides/img%20(31).webp">
          </div>
        </div>
      </div>

    
        
    
        
            
      $('.carousel').carousel({
        touch: true // default
      })