Bootstrap > Carousel

Sliding image in Bootstrap

How to slide the image using carousel feature in Bootstrap

Sliding image

Bootstrap uses carousel to create sliding of the image

        .carousel-inner > .item > img,
        .carousel-inner > .item > a > img {
            width: 70%;
            margin: auto;
    <h2>Image sliding</h2>
    <div class="container">
        <div id="myCarousel" class="carousel slide" data-ride="carousel">
            <ol class="carousel-indicators">
                <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
                <li data-target="#myCarousel" data-slide-to="1"></li>
                <li data-target="#myCarousel" data-slide-to="2"></li>
                <li data-target="#myCarousel" data-slide-to="3"></li>
            <div class="carousel-inner">
                <div class="item active">
                    <img src="download.png" />                 

                <div class="item">
                    <img src="download (1).png" />

                <div class="item">
                    <img src="download2.jpg" />

                <div class="item">
                    <img src="download 3.jpg" />

            <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
                <span class="glyphicon glyphicon-chevron-left"></span>
                <span class="sr-only">Previous</span>
            <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
                <span class="glyphicon glyphicon-chevron-right" ></span>
                <span class="sr-only">Next</span> 
  • In the above code snippet we have defined sliding an image using carousel, we have taken div with class attribute value as   container , we have taken another div with id as mycarousel with class attribute value carousel slide and data-ride as carousel, we have used style sheet to define the carousel-inner values to set margin and width 
  • In the next line we have value of class attribute carousel-indicators with ol elements as data-target as mycarousel  with data-slide as 0 to 3 and  data-slide ="0" is in active state
  • In the next line we are having div with value of  class attribute carousel-inner  to define the images to slide
  • In the next line we are having two anchor tags <a> tag to define the left carousel-control and right carousel-control  with href as #mycarousel, role as button  and data-slide=previous and next, the span with class attribute  glyphicon icons as chevron left and right     


 Views: 6627 | Post Order: 44

Write for us

Hosting Recommendations