Bootstrap 5 Carousel Options
Last Updated :
29 Jul, 2024
Bootstrap 5 Carousel options which can be used to customize the carousel and use it more efficiently. These options can be passed to the carousel through data attributes or using JavaScript. To add the options using data attributes we just need to add the name of the option data-bs-* by replacing the star in it.
Bootstrap 5 Carousel Options Attribute:
- data-bs-*: Options should be passed for data attributes.
Bootstrap 5 Carousel Options: These are the option which are replaceable with * of data-bs-*.
- interval: Sets the time delay (in milliseconds) between each slide in an automated cycling system. If false, the carousel won't spin on its own. The type is number and the default value is 5000ms.
- keyboard: Defines whether keyboard actions should cause the carousel to move. The left and right arrow keys on the keyboard may be used to go to the previous and next slide of a carousel when it has the focus. The type is boolean and the default value is "true".
- pause: It pauses the cycling of the carousel when the mouse pointer enters the carousel and resumes the cycling when the mouse pointer leaves the carousel, by default. If set to false, hovering over the carousel won't pause it. The type is a string.
- ride: After the user manually cycles the first item, the carousel automatically plays. Carousel autoplay if set to "carousel"; otherwise, it does not. The type is a string and the default value is "false".
- wrap: Indicates whether the carousel should have hard stops or run constantly (i.e stop at the last slide). The type is boolean and the default value is "true".
- touch(boolean : true{default value}): Indicates whether touchscreen left/right swipe interactions should be supported for the carousel. The type is boolean and the default value is "true"
Syntax:
<div id=".." class="carousel" data-bs-*=value>
<!-- Carousel Content --!>
</div>
Note: The * in the data-bs-* is replaced by the name of one of the options given above.
Example 1: The code below demonstrates the usage of the three options data-bs-keyboard, data-bs-interval and data-bs-pause. To check the keyboard option click on the link provided in the caption and check on a desktop or PC.
HTML
<!doctype html>
<html lang="en">
<head>
<link href=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity=
"sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous">
<script src=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity=
"sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous">
</script>
</head>
<body>
<h1 class="m-4 text-success">
GeeksforGeeks
</h1>
<h4 class="ms-4">
Bootstrap 5 Carousel Options
</h4>
<div class="container mb-4 p-4">
<div id="carouselExampleSlidesOnly"
class="carousel slide"
data-bs-ride="carousel"
data-bs-pause="false"
data-bs-keyboard="false">
<div class="carousel-inner">
<div class="carousel-item bg-light active"
data-bs-interval="2000">
<h1 class="m-4 text-success" >
This is the first slide</h1>
<h4 class="ms-4">
This slide has a time delay of 2000ms
</h4>
</div>
<div class="carousel-item bg-light"
data-bs-interval="4000">
<h1 class="m-4 text-danger">
This is the second slide</h1>
<h4 class="ms-4">
This slide has a time delay of 4000ms
<br>
In this carousel the pause is false and
it doesn't stops when we hover.
</h4>
</div>
<div class="carousel-item bg-light"
data-bs-interval="6000">
<h1 class="m-4 text-warning">
This is the third slide</h1>
<h4 class="ms-4">
This slide has a time delay of 6000ms
<br>
Here the keyboard option is set to False
</h4>
</div>
</div>
</div>
</div>
</body>
</html>
Output:
Example 2: The code below demonstrates the usage of the options data-bs-ride and data-bs-touch.
HTML
<!doctype html>
<html lang="en">
<head>
<link href=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet" integrity=
"sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous">
<script src=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity=
"sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous">
</script>
</head>
<body>
<h1 class="m-4 text-success">
GeeksforGeeks
</h1>
<h4 class="ms-4">
Bootstrap 5 Carousel Options
</h4>
<div class="container mb-4 p-4
text-light text-center">
<div id="carouselExample2"
class="carousel slide carousel-fade"
data-bs-ride="false"
data-bs-touch="true">
<div class="carousel-inner">
<div class="carousel-item bg-dark active pb-4">
<h1 class="m-4 text-success">
This is the first slide
</h1>
<img src=
"http://www.geeksforgeeks.org/wp-content/uploads/gfg_200X200-1.png"
width="25%" alt="GFG LOGO">
</div>
<div class="carousel-item bg-dark pb-4">
<h1 class="m-4 text-warning text-center">
This is the second slide
</h1>
<div class="text-center">
<img src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/20190710102234/download3.png"
width="25%" alt="GFG LOGO">
</div>
</div>
<div class="carousel-item bg-dark pb-4">
<h1 class="m-4 text-warning">
This is the third slide
</h1>
<div class="text-center">
<img src=
"https://media.geeksforgeeks.org/wp-content/uploads/20221128115907/gfglogo.png"
width="25%" alt="GFG LOGO">
</div>
</div>
</div>
<button class="carousel-control-prev"
type="button"
data-bs-target="#carouselExample2"
data-bs-slide="prev">
<span class="carousel-control-prev-icon"></span>
<span class="visually-hidden">
Previous
</span>
</button>
<button class="carousel-control-next"
type="button"
data-bs-target="#carouselExample2"
data-bs-slide="next">
<span class="carousel-control-next-icon"></span>
<span class="visually-hidden">
Next
</span>
</button>
</div>
</div>
</body>
</html>
Output:
Reference: https://getbootstrap.com/docs/5.0/components/carousel/#options
Similar Reads
Bootstrap 5 Carousel Slides only Bootstrap 5 Carousel Slides only is a type of carousel where there is nothing in the slides of the carousel like the previous, next buttons, captions, and indicators. This carousel is the easiest one to implement as it has the least amount of components but this has the least user accessibility.Boot
3 min read
Bootstrap 5 Carousel With Controls Bootstrap 5 Carousel With controls means we can add controls to the Carousel for changing the slides of the carousel. Note: This can be achieved using HTML <button> as well as HTML <a> tag.Bootstrap 5 Carousel With Controls Classes:carousel-control-prev: This class is used for the carous
2 min read
Bootstrap 5 Carousel With Indicators Bootstrap 5 Carousel With indicators are used to create indicators in the carousel. We can click on these indicators, to change from one slide to another.Bootstrap 5 Carousel With Indicators Classes:carousel-indicators: This class is used for including carousel indicators in the HTML div container.S
2 min read
Bootstrap 5 Carousel With Captions Bootstrap 5 Carousel With captions means we can add a class carousel-caption to the carousel items to add a caption for them.Bootstrap 5 Carousel With Captions Class:carousel-caption: This class is used for giving carousel captions.Syntax<div class="carousel-caption"> ...</div>Example 1:
2 min read
Bootstrap 5 Carousel Crossfade Bootstrap 5 Carousel Crossfade is used to create a carousel animate slide show effect in Crossfade style. To make this effect, the .carousel-fade class is used.Carousel Crossfade used Class:.carousel-fade: This class is used to add the fade effect in the carousel slide animation.Syntax:<div id="G
2 min read
Bootstrap 5 Carousel Individual .carousel-item interval Bootstrap 5 Carousel Individual .carousel-item interval is used to give time intervals to individual carousel items by which the carousel items will be automatically cycled at the given intervals of time.Bootstrap 5 Carousel Classes:carousel-item: This class specifies each item of the carousel.Boots
2 min read
Bootstrap 5 Carousel Disable Touch Swiping Bootstrap5 Carousel Disable Touch Swiping can be used to disable the left/right swipe of the slides with touch on a touchscreen, by specifying the data-bs-touch attribute. Setting the data-bs-interval attribute as false will stop the autoplay of the slides.Disable touch swiping Class: There is no cl
3 min read
Bootstrap 5 Carousel Dark variant Bootstrap 5 Carousel Dark variant is by default, controls, indicators, and captions have white colors. But, for Darker controls, indicators, and captions, we can add a class carousel-dark to the carousel. Used class:carousel-dark: This class is used to include the dark variant for the carousel conta
2 min read
Bootstrap 5 Carousel Custom Transition Bootstrap 5 Carousel transition can be customized with the help of the SASS variables that help to set the duration of the transition. The transform transition will need to be defined first if multiple transitions are implemented. In other words, the transition can be set to a custom setting using t
3 min read
Bootstrap 5 Carousel SASS Bootstrap 5 Â Carousel SASS has a set of variables with default values that can be changed to customize the Carousel.Bootstrap 5 Carousel SassVariables: Carousel variables have a default value that can be customized to make a new Carousel layout.Default values of Carousel SASS variables$carousel-cont
4 min read