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"
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-intervalanddata-bs-pause. To check the keyboard option click on the link provided in the caption and check on a desktop or PC.
Output:
Example 2: The code below demonstrates the usage of the optionsdata-bs-ride and data-bs-touch.