Bootstrap 4 | Carousel

The Bootstrap Carousel is used to create an image slide show for the webpage to make it look more attractive. It can be included in the webpage using bootstrap.js or bootstrap.min.js. Carousels are not supported properly in Internet Explorer, this is because they use CSS3 transitions and animations to achieve the slide effect.

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html lang="en"
<head
    <title>Carousel</title
      
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
  
    <link rel="stylesheet" href=
      
    <script src=
    </script>
      
    <script src=
    </script>
      
    <script src=
    </script>
      
    <style>
  /* Make the image fully responsive */
  .carousel-inner img {
      width: 100%;
      height: 100%;
  }
  </style>
</head
  
<body>
    <div id="GFG" class="carousel slide" data-ride="carousel">
      
    <!-- Indicators -->
    <ul class="carousel-indicators">
        <li data-target="#GFG" data-slide-to="0" class="active"></li>
        <li data-target="#GFG" data-slide-to="1"></li>
        <li data-target="#GFG" data-slide-to="2"></li>
        <li data-target="#GFG" data-slide-to="3"></li>
    </ul>
        
    <!-- The slideshow -->
    <div class="carousel-inner">
        <div class="carousel-item active">
            <img src=
            alt="GFG" width="600" height="400">
        </div>
          
        <div class="carousel-item">
            <img src=
            alt="GFG" width="600" height="600">
        </div>
          
        <div class="carousel-item">
            <img src=
            alt="GFG" width="600" height="400">
        </div>
          
        <div class="carousel-item">
            <img src=
            alt="GFG" width="600" height="400">
        </div>
    </div>
        
      <a class="carousel-control-prev" href="#GFG" data-slide="prev">
        <span class="carousel-control-prev-icon"></span>
      </a>
      <a class="carousel-control-next" href="#GFG" data-slide="next">
        <span class="carousel-control-next-icon"></span>
      </a>
    </div>
</body
  
</html>                    

chevron_right


Output:

Add Captions to Slides: Use .carousel-caption inside .carousel-item class is used to add caption to the slide.

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html lang="en"
<head
    <title>Carousel</title
      
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
  
    <link rel="stylesheet" href=
      
    <script src=
    </script>
      
    <script src=
    </script>
      
    <script src=
    </script>
      
    <style>
        /* Set the image size */
        .carousel-inner img {
            width: 100%;
          
        }
    </style>
</head
  
<body>
    <div id="GFG" class="carousel slide" data-ride="carousel">
      
    <!-- Indicators -->
    <ul class="carousel-indicators">
        <li data-target="#GFG" data-slide-to="0" class="active"></li>
        <li data-target="#GFG" data-slide-to="1"></li>
        <li data-target="#GFG" data-slide-to="2"></li>
    </ul>
      
    <!-- The slideshow -->
    <div class="carousel-inner">
        <div class="carousel-item active">
            <img src=
            alt="GFG" width="600" height="400">
              
            <div class="carousel-caption">
                <h3 class="text-warning">
                    GeeksforGeeks: Interview Preparation Caption
                </h3>
            </div>   
        </div>
          
        <div class="carousel-item">
            <img src=
            alt="GFG" width="600" height="400">
              
            <div class="carousel-caption">
                <h3 class="text-warning">
                    GeeksforGeeks: Geeks Classes Caption
                </h3>
            </div
        </div>
          
        <div class="carousel-item">
            <img src=
            alt="GFG" width="600" height="400">
              
            <div class="carousel-caption">
                <h3 class="text-warning">
                    GeeksforGeeks: Geeks Classes Caption
                </h3>
            </div
        </div>
    </div>
      
    <a class="carousel-control-prev" href="#GFG" data-slide="prev">
        <span class="carousel-control-prev-icon"></span>
    </a>
    <a class="carousel-control-next" href="#GFG" data-slide="next">
        <span class="carousel-control-next-icon"></span>
    </a>
    </div>
</body
  
</html>                                

chevron_right


Output:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.