Carousel

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 markup. 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.).

The animation effect of this component is dependent on the prefers-reduced-motion media query. See the reduced motion section of our accessibility documentation.

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

Lastly, if you’re building our JavaScript from source, it requires util.js.

Examples

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. Add and customize 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 src="../assets/img-temp/500x280/img1.jpg" class="d-block w-100" alt="First slide">
                            </div>
                            <div class="carousel-item">
                              <img src="../assets/img-temp/500x280/img2.jpg" class="d-block w-100" alt="Second slide">
                            </div>
                            <div class="carousel-item">
                              <img src="../assets/img-temp/500x280/img3.jpg" class="d-block w-100" alt="Third slide">
                            </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 src="../assets/img-temp/500x280/img1.jpg" class="d-block w-100" alt="First slide">
                            </div>
                            <div class="carousel-item">
                              <img src="../assets/img-temp/500x280/img2.jpg" class="d-block w-100" alt="Second slide">
                            </div>
                            <div class="carousel-item">
                              <img src="../assets/img-temp/500x280/img3.jpg" class="d-block w-100" alt="Third slide">
                            </div>
                          </div>
                          <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
                            <span aria-hidden="true">
                              <svg class="duik-icon-svg-white duik-icon-svg-2x" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 18 9 12 15 6"></polyline></svg>
                            </span>
                            <span class="sr-only">Previous</span>
                          </a>
                          <a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
                            <span aria-hidden="true">
                              <svg class="duik-icon-svg-white duik-icon-svg-2x" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 18 15 12 9 6"></polyline></svg>
                            </span>
                            <span class="sr-only">Next</span>
                          </a>
                        </div>
                      
                    

With indicators

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

                      
                        <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
                          <ol class="carousel-indicators">
                            <li data-target="#carouselExampleIndicators" data-slide-to="0" class="rounded active"></li>
                            <li data-target="#carouselExampleIndicators" data-slide-to="1" class="rounded"></li>
                            <li data-target="#carouselExampleIndicators" data-slide-to="2" class="rounded"></li>
                          </ol>

                          <div class="carousel-inner">
                            <div class="carousel-item active">
                              <img class="d-block w-100" src="../assets/img-temp/500x280/img1.jpg" alt="First slide">
                            </div>

                            <div class="carousel-item">
                              <img class="d-block w-100" src="../assets/img-temp/500x280/img2.jpg" alt="Second slide">
                            </div>

                            <div class="carousel-item">
                              <img class="d-block w-100" src="../assets/img-temp/500x280/img3.jpg" alt="Third slide">
                            </div>
                          </div>

                          <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
                            <span aria-hidden="true">
                              <svg class="duik-icon-svg-white duik-icon-svg-2x" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 18 9 12 15 6"></polyline></svg>
                            </span>
                            <span class="sr-only">Previous</span>
                          </a>
                          <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
                            <span aria-hidden="true">
                              <svg class="duik-icon-svg-white duik-icon-svg-2x" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 18 15 12 9 6"></polyline></svg>
                            </span>
                            <span class="sr-only">Next</span>
                          </a>
                        </div>