Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

Bootstrap 4 | Carousel

  • Last Updated : 28 Jul, 2021

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: 
 

html




<!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>                   

Output: 
 

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

html




<!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>                               

Output: 
 

Supported Browser:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari



My Personal Notes arrow_drop_up
Recommended Articles
Page :