Bootstrap Carousel Plugin

Bootstrap is offering a remarkable feature of carousel and easy to embed in website. This Bootstrap Carousel Plugin is flexible and responsive and allows images, videos and any kind of content which you want to use within the carousel area.

If you want to implement functionality of this plugin individually, simple include the carousel.js file along the other JS files. Else as we have discussed in the tutorial of Bootstrap Plugin Overview, you can include bootstrap.jsor the minified bootstrap.min.js.


Here is a simple slideshow below shows a generic component for cycling through elements like a carousel. To use the carousel you simple need a markup code. This is only class based development you do not need for data attributes for carousel plugin.

Optional Captions

If you want to like add captions to your slides easily with the .carousel-caption element within any .item. Place just about any optional HTML within there and it will be automatically aligned and formatted. Use the following code to display caption in the slideshow:


Via data attributes

Use data attributes to easily control the position of the carousel.

  • Attribute data-slide accepts the keywords prev or next, which alters the slide position relative to its current position.

  • Alternatively use data-slide-to to pass a raw slide index to the carousel data-slide-to=”2″, which shifts the slide position to a particular index beginning with 0.

  • The data-ride=”carousel” attribute is used to mark a carousel as animating starting at page load.

Via JavaScript

The carousel can be manually called with JavaScript as below:


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

Option Name Type Default Data attribute name Description
interval number 5000 data-interval The amount of time to delay between automatically cycling an item. If false, carousel will not automatically cycle.
pause string "hover" data-pause Pauses the cycling of the carousel on mouseenter and resumes the cycling of the carousel on mouseleave.
wrap boolean true data-wrap Whether the carousel should cycle continuously or have hard stops.


Here are some useful methods to use carousel code.

Method Description
.carousel(options) Initializes the carousel with an optional options object and starts cycling through items.
.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..


This example shows the usage of above listed methods.


Bootstrap’s carousel class exposes two events for hooking into carousel functionality which are listed below.

Both events have the following additional properties:

  • direction: The direction in which the carousel is sliding (either "left" or "right").
  • relatedTarget: The DOM element that is being slid into place as the active item.
Event Description This event fires immediately when the slide instance method is invoked.. This event is fired when the carousel has completed its slide transition.


The following example demonstrates the usage of events:

Leave a Reply

Your email address will not be published. Required fields are marked *