A slideshow component for cycling through elements—images or slides of text—like a carousel. 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.). Nested carousels are not supported.
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel"> <ol class="carousel-indicators"> <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li> <li data-target="#carousel-example-generic" data-slide-to="1"></li> <li data-target="#carousel-example-generic" data-slide-to="2"></li> </ol> <div class="carousel-inner" role="listbox"> <div class="carousel-item active"> <img src="..." alt="First slide"> </div> <div class="carousel-item"> <img src="..." alt="Second slide"> </div> <div class="carousel-item"> <img src="..." alt="Third slide"> </div> </div> <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev"> <span class="icon-prev" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a> <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next"> <span class="icon-next" aria-hidden="true"></span> <span class="sr-only">Next</span> </a> </div>
Transition animations not supported in Internet Explorer 9
Bootstrap exclusively uses CSS3 for its animations, but Internet Explorer 9 doesn’t support the necessary CSS properties. Thus, there are no slide transition animations when using that browser. We have intentionally decided not to include jQuery-based fallbacks for the transitions.
Initial active element required
.active class needs to be added to one of the slides. Otherwise, the carousel will not be visible.
Add captions to your slides easily with the
.carousel-caption element within any
.carousel-item. Place just about any optional HTML within there and it will be automatically aligned and formatted.
The carousel component is generally not compliant with accessibility standards. If you need to be compliant, please consider other options for presenting your content.
Carousels require the use of an
id on the outermost container (the
.carousel) for carousel controls to function properly. When adding multiple carousels, or when changing a carousel’s
id, be sure to update the relevant controls.
Via data attributes
Use data attributes to easily control the position of the carousel.
data-slide accepts the keywords
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
Call carousel manually with:
data-, as in
|interval||number||5000||The amount of time to delay between automatically cycling an item. If false, carousel will not automatically cycle.|
|pause||string||"hover"||Pauses the cycling of the carousel on mouseenter and resumes the cycling of the carousel on mouseleave.|
|wrap||boolean||true||Whether the carousel should cycle continuously or have hard stops.|
|keyboard||boolean||true||Whether the carousel should react to keyboard events.|
Initializes the carousel with an optional options
object and starts cycling through items.
Cycles through the carousel items from left to right.
Stops the carousel from cycling through items.
Cycles the carousel to a particular frame (0 based, similar to an array).
Cycles to the previous item.
Cycles to the next item.
Bootstrap’s carousel class exposes two events for hooking into carousel functionality. Both events have the following additional properties:
direction: The direction in which the carousel is sliding (either
relatedTarget: The DOM element that is being slid into place as the active item.
All carousel events are fired at the carousel itself (i.e. at the
|slide.bs.carousel||This event fires immediately when the
|slid.bs.carousel||This event is fired when the carousel has completed its slide transition.|