VOOZH about

URL: https://www.geeksforgeeks.org/bootstrap/bootstrap-5-carousel-custom-transition/

⇱ Bootstrap 5 Carousel Custom Transition - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Bootstrap 5 Carousel Custom Transition

Last Updated : 23 Jul, 2025

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 the $carousel-transition-duration and $carousel-transitionSASS variables. For this, we have to get the SASS version and change the variable's values there.   

Carousel Custom transition variables:

  • $carousel-transition-duration(.6s): This variable is used to change the duration by which the transition of one slide changes to the next or previous slide.
  • $carousel-transition (transform $carousel-transition-duration ease-in-out): This variable is used to change the transition effects of the carousel slides.

Steps to override SCSS of Bootstrap:

Step 1: Install Bootstrap using the following command:

npm i bootstrap

Step 2: Create your custom SCSS file and write the variable you want to override. Then include the bootstrap SCSS file using import.

$variable_to_override: value
@import "../node_modules/bootstrap/scss/bootstrap.scss";

Step 3: Convert the SCSS file to CSS using a live server extension.

Step 4: Include the CSS file in your HTML file.

<link rel="stylesheet" href="style.css">

Project Structure:

👁 Image

Syntax:

$variable_to_override: value

Example 1: The code below demonstrated how to change and manipulate the $carousel-transition-duration and $carousel-transition variables to change the carousel's animation. The carousel which is implemented is a carousel with slides only.

  • styles.scss:
  • styles.css: The above SCSS file is compiled into this CSS file (only the changes shown). This file is used in the below "index.html" file.
  • index.html:

Output:

Example 2: The code below demonstrated how to reduce the $carousel-transition-duration and change $carousel-transition variables to change the carousel's animation. The carousel which is implemented is a carousel with text and images and has a carousel-fade class which adds a fading transformation.

  • styles.scss:
  • styles.css: The above SCSS file is compiled into this CSS file (only the changes shown). This file is included in the below "index.html" file.
  • index.html:

Output:

Reference: https://getbootstrap.com/docs/5.0/components/carousel/#custom-transition

Comment
Article Tags:

Explore