Animations

Bootstrap 5 Animations

Subtle and smooth MDB animations provide the user with a unique experience when interacting with UI. There are several dozen animations at your disposal along with many customization and implementation options.

Bootstrap 5 animations imitate motions for web elements. +70 animations generated by CSS only, work on every browser.

Note: Read the API tab to find all available options and advanced customization

Video tutorial

Move the mouse over the squares below to launch the animation.

fade-in
fade-in-down
fade-in-left
fade-in-right
fade-in-up
fade-out
fade-out-down
fade-out-left
fade-out-right
fade-out-up
slide-in-down
slide-in-left
slide-in-right
slide-in-up
slide-out-down
slide-out-left
slide-out-right
slide-out-up
slide-down
slide-left
slide-right
slide-up
zoom-in
zoom-out
tada
pulse

Basic example

The easiest way to implement the animation is to use data-mdb-attributes. In the example below, we use the icon <i class="fas fa-car-side fa-3x"></i> and add the attributes data-mdb-toggle="animation" data-mdb-animation-reset="true" data-mdb-animation="slide-out-right" to give it animation on click.

data-mdb-toggle="animation" is an obligatory attribute for each animation.

data-mdb-animation-reset="true" lets you decide if the animation can be repeated

data-mdb-animation="slide-right" lets you specify which animation apply to the element. In the demo section above you can find available animations.

Click the car to start the animation.

        
            
          <i
            data-mdb-toggle="animation"
            data-mdb-animation-reset="true"
            data-mdb-animation="slide-right"
            class="fas fa-car-side fa-3x"
          ></i>
        
        
    

Animation list

By default, you have access to the basic animations. However, you can also import _animate-extended.scss and compile extended animations.

Basic Animations

  • fade-in
  • fade-in-down
  • fade-in-left
  • fade-in-right
  • fade-in-up
  • fade-out
  • fade-out-down
  • fade-out-left
  • fade-out-right
  • fade-out-up
  • slide-in-down
  • slide-in-left
  • slide-in-right
  • slide-in-up
  • slide-out-down
  • slide-out-left
  • slide-out-right
  • slide-out-up
  • slide-down
  • slide-left
  • slide-right
  • slide-up
  • zoom-in
  • zoom-out
  • tada
  • pulse

Extended Animations

  • drop-in
  • drop-out
  • fly-in
  • fly-in-up
  • fly-in-down
  • fly-in-left
  • fly-in-right
  • fly-out
  • fly-out-up
  • fly-out-down
  • fly-out-left
  • fly-out-right
  • browse-in
  • browse-out
  • browse-out-left
  • browse-out-right
  • jiggle
  • flash
  • shake
  • glow

Launch options

There are several options for launching the animation.

On click

Animation on click is a default launching option, so it does not require any data-mdb-attribute.

        
            
            <i
              data-mdb-toggle="animation"
              data-mdb-animation-reset="true"
              data-mdb-animation="slide-right"
              class="fas fa-car-side fa-3x"
            ></i>
          
        
    

On hover

Use data-mdb-animation-start="onHover" to launch the animation on mouse hover.

        
            
            <i
              data-mdb-toggle="animation"
              data-mdb-animation-start="onHover"
              data-mdb-animation-reset="true"
              data-mdb-animation="slide-right"
              class="fas fa-car-side fa-3x"
            ></i>
          
        
    

On Load

Use data-mdb-animation-start="onLoad" to start the animation after loading the page. Refresh your browser to see this effect.

        
            
            <i
              data-mdb-toggle="animation"
              data-mdb-animation="zoom-in"
              data-mdb-animation-start="onLoad"
              class="fas fa-car-side fa-3x"
            ></i>
          
        
    

Manually

Use data-mdb-animation-start="manually" to initialize the component without animating, adding hover, clicking or scrolling events and use the animationStart method when you want to start the animation.

        
            
            <i
              data-mdb-toggle="animation"
              data-mdb-animation="zoom-in"
              data-mdb-animation-start="onLoad"
              class="fas fa-car-side fa-3x"
            ></i>
          
        
    

On scroll

Use data-mdb-animation-start="onScroll" to launch the animation when you scroll the page and reach the element.

Notice that the animation will launch only once - even if you reach it when scrolling multiple times.

        
            
            <i
              data-mdb-toggle="animation"
              data-mdb-animation-start="onScroll"
              data-mdb-animation="slide-in-left"
              class="fas fa-car-side fa-3x"
            ></i>
          
        
    

Repeat animation on scroll

If you want to launch the animation every time it's reached when scrolling use data-mdb-animation-on-scroll="repeat".

        
            
            <i
              data-mdb-toggle="animation"
              data-mdb-animation-start="onScroll"
              data-mdb-animation-on-scroll="repeat"
              data-mdb-animation="slide-in-left"
              class="fas fa-car-side fa-3x"
            ></i>
          
        
    

Show on load

If you use animation onScroll, by default all elements are visible when the page is loaded. They disappear and begin to animate after the first scroll. You can change this by setting data-mdb-animation-show-on-load="false". However, remember that this may have a negative impact on SEO.

        
            
            <i
              data-mdb-toggle="animation"
              data-mdb-animation-start="onScroll"
              data-mdb-animation-on-scroll="repeat"
              data-mdb-animation-show-on-load="false"
              data-mdb-animation="slide-in-left"
              class="fas fa-car-side fa-3x"
            ></i>
          
        
    

Examples

Examples of practical usage of the animation.

Launching via external element

Click or hover the button to launch the animation.

        
            
            <div class="d-flex justify-content-around">
              <div>
                <button
                  class="btn btn-primary me-5"
                  data-mdb-toggle="animation"
                  data-mdb-animation-target="#animate-click"
                >
                  Animation on Click
                </button>
                <i
                  id="animate-click"
                  data-mdb-animation="slide-out-right"
                  data-mdb-animation-start="onClick"
                  data-mdb-animation-reset="true"
                  class="fas fa-car-side fa-3x"
                ></i>
              </div>
              <div>
                <button
                  class="btn btn-primary me-5"
                  data-mdb-toggle="animation"
                  data-mdb-animation-target="#animate-hover"
                >
                  Animation on Hover
                </button>
                <i
                  id="animate-hover"
                  data-mdb-animation="slide-out-right"
                  data-mdb-animation-start="onHover"
                  data-mdb-animation-reset="true"
                  class="fas fa-car-side fa-3x"
                ></i>
              </div>
            </div>
          
        
    

Start animation manually

You can use the animationStart and animationStop methods to start or stop the animation at the right moment

        
            
            <i id="manually-example" class="fas fa-car-side fa-3x"></i>
            <button id="manually-btn-start" class="btn btn-primary ms-3">start</button>
            <button id="manually-btn-stop" class="btn btn-primary ms-3">stop</button>
          
        
    
        
            
            const manuallyEl = document.getElementById('manually-example');
            const manuallyBtnStart = document.getElementById('manually-btn-start');
            const manuallyBtnStop = document.getElementById('manually-btn-stop');
            const manually = new mdb.Animate(manuallyEl, { 
              animation: 'fade-in',
              animationStart: 'manually',
              animationRepeat: true,
            });
            manuallyBtnStart.addEventListener('click', () => {
             manually.startAnimation(); 
            });
            manuallyBtnStop.addEventListener('click', () => {
              manually.stopAnimation();
            });
          
        
    

Change animation type

You can change the element's animation type at any time using the changeAnimationType() method.

        
            
            <i id="change-animation-type-example" class="fas fa-car-side fa-3x"></i>
            <button id="change-animation-type-btn" class="btn btn-primary ms-3">
              change animation
            </button>
          
        
    
        
            
            const changeAnimationEl = document.getElementById('change-animation-type-example');
            const changeAnimationBtn = document.getElementById('change-animation-type-btn');
            let animation = 'zoom-in';
            const changeAnimation = new mdb.Animate(changeAnimationEl, {
              animation: animation, 
              animationStart: 'onLoad',
              animationDuration: 1000,
              animationRepeat: true,
            });
            
            changeAnimation.init();

            changeAnimationBtn.addEventListener('click', () => {
              if (animation === 'zoom-in') {
                animation = 'zoom-out'
              } else {
                animation = 'zoom-in'
              }
              changeAnimation.stopAnimation();
              changeAnimation.changeAnimationType(animation);
              changeAnimation.startAnimation();
            })
          
        
    

List group

Click "Add" button to add a new item to the list.

  • Cras justo odio
  • Dapibus ac facilisis in
  • Vestibulum at eros
        
            
            <div class="d-flex">
              <div class="card" style="width: 18rem;">
                <ul id="example-list" class="list-group list-group-flush">
                  <li class="list-group-item">Cras justo odio</li>
                  <li class="list-group-item">Dapibus ac facilisis in</li>
                  <li class="list-group-item">Vestibulum at eros</li>
                </ul>
              </div>
              <div class="ms-3">
                <button class="btn btn-primary" id="add">add</button>
              </div>
            </div>
          
        
    
        
            
            let elementNumber = 1;
            const bindRemoveClickEvent = (el) => {
              const element = el;

              element.addEventListener('click', () => {
                const prevElement = element.previousElementSibling ? element.previousElementSibling : element;
                const animation = element === prevElement ? 'fade-out' : 'slide-out-up';
                
                prevElement.style.zIndex = '1';

                element.addEventListener('animationend', () => {
                  element.remove();
                  prevElement.style.zIndex = '0';
                });

                element.classList.add('animation', 'faster', animation);
              });
            };

            const addNewOption = () => {
              const element = document.getElementById('example-list');
              const newElement = document.createElement('li');
              const lastElement = element.lastElementChild || element;
              const animation = element === lastElement ? 'fade-in' : 'slide-in-down';
              
              newElement.innerText = `element ${elementNumber}`;
              lastElement.style.zIndex = '1';
              newElement.classList.add('list-group-item', 'animation', 'faster', animation);
              
              newElement.addEventListener('animationend', () => {
                lastElement.style.zIndex = '0';
                newElement.classList.remove('animation', 'faster', animation);
              });

              bindRemoveClickEvent(newElement);
              element.appendChild(newElement);
              elementNumber += 1;
            };

            document.querySelectorAll('#example-list li').forEach((el) => {
              bindRemoveClickEvent(el);
            });
            
            document.getElementById('add').addEventListener('click', () => {
              addNewOption();
            });
          
        
    

Accordion

Click the collapsible group of the accordion to see the animation.

Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.

Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.

Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
        
            
            <div class="accordion" id="accordionExample">
              <div class="card">
                <div class="card-header bg-white" id="headingOne">
                  <h2 class="mb-0">
                    <button
                      class="btn btn-link btn-block text-start"
                      type="button"
                      data-mdb-toggle="collapse"
                      data-mdb-target="#collapseOne"
                      data-mdb-animation-target="#collapseOne"
                      aria-expanded="true"
                      aria-controls="collapseOne"
                    >
                      Collapsible Group Item #1
                    </button>
                  </h2>
                </div>
                <div
                  id="collapseOne"
                  class="collapse show"
                  aria-labelledby="headingOne"
                  data-mdb-parent="#accordionExample"
                >
                  <div class="card-body">...</div>
                </div>
              </div>
              <div class="card">
                <div class="card-header bg-white" id="headingTwo">
                  <h2 class="mb-0">
                    <button
                      class="btn btn-link btn-block text-start collapsed"
                      type="button"
                      data-mdb-toggle="collapse"
                      data-mdb-target="#collapseTwo"
                      data-mdb-animation-target="#collapseTwo"
                      aria-expanded="false"
                      aria-controls="collapseTwo"
                    >
                      Collapsible Group Item #2
                    </button>
                  </h2>
                </div>
                <div
                  id="collapseTwo"
                  class="collapse"
                  aria-labelledby="headingTwo"
                  data-mdb-parent="#accordionExample"
                >
                  <div class="card-body">...</div>
                </div>
              </div>
              <div class="card">
                <div class="card-header bg-white" id="headingThree">
                  <h2 class="mb-0">
                    <button
                      class="btn btn-link btn-block text-start collapsed"
                      type="button"
                      data-mdb-toggle="collapse"
                      data-mdb-target="#collapseThree"
                      data-mdb-animation-target="#collapseThree"
                      aria-expanded="false"
                      aria-controls="collapseThree"
                    >
                      Collapsible Group Item #3
                    </button>
                  </h2>
                </div>
                <div
                  id="collapseThree"
                  class="collapse"
                  aria-labelledby="headingThree"
                  data-mdb-parent="#accordionExample"
                >
                  <div class="card-body">...</div>
                </div>
              </div>
            </div>
          
        
    
        
            
            document.querySelectorAll('button[data-mdb-toggle="collapse"]').forEach((el) => {
              const animate = new mdb.Animate(el, {
                animation: 'fade-in-up',
                delay: '500',
                duration: '500',
              });
              animate.init();
            });
          
        
    

Animations - API


Usage

Via CSS class

        
            
          <i class="fas fa-car-side fa-3x animation slide-out-right"></i>
        
        
    

Via data attributes

        
            
          <i
            data-mdb-toggle="animation"
            data-mdb-animation="tada"
            data-mdb-animation-start="onLoad"
            class="fas fa-star fa-3x"
          ></i>
        
        
    

Via JavaScript

JavaScript with CSS classes:
Note: After JS initializes the animation, the classes responsible for animations will not work.

        
            
        const element = document.getElementById('example');
        const animate = new mdb.Animate(element, { animation: 'tada', });
        animate.init();
        
        
    

Via data jQuery

        
            
          $('#example').animate({ animation: 'tada' });
        
        
    

Options

Name Data attribute Type Default Description
animation data-mdb-animation String 'fade' Changes animation
animationStart data-mdb-animation-start String 'animationOnClick' Set how to run the animation (onClick, onLoad, onScroll, onHover, manually)
animationReset data-mdb-animation-reset Boolean false Set to reset the animation after it finishes
animationShowOnLoad data-mdb-animation-show-on-load Bollean true Set false to start the scrolling animation immediately after the page loads. NOTE: this will hide elements that are not currently visible on the screen and this may have a negative impact on SEO
animationOnScroll data-mdb-animation-on-scroll String once Set repeat to start the animation each time the item appears on the screen
onStart - Function Callback function fires after start animation
onEnd - Function Callback function fires after end animation
onHide - Function Callback function fires after show element
onShow - Function Callback function fires after hide element
animationOffset data-mdb-animation-offset Number 0 Set offset for animate on scroll
animationDelay data-mdb-animation-delay Number 0 Set animation delay
animationDuration data-mdb-animation-duration number 500 Set animation duration
animationReverse data-mdb-animation-reverse Boolean false Set true to played animation forwards first, then backwards
animationInterval data-mdb-animation-interval Number 0 Set the time interval between animations
animationRepeat data-mdb-animation-repeat Boolean/Number false Set animation repeat - set true to repeat infinity or enter the number of times the animation should repeat

Methods

Name Description Example
dispose Destroy animations with this method animation.dispose()
getInstance Static method which allows you to get the animation instance associated to a DOM element. Animate.getInstance(animateEl)
getOrCreateInstance Static method which returns the animation instance associated to a DOM element or create a new one in case it wasn't initialized. Animate.getOrCreateInstance(animateEl)
startAnimation Start animating the element animation.startAnimation()
stopAnimation Stop animating the element animation.stopAnimation()
changeAnimationType Change the animation type of an element animation.changeAnimationType()
        
            
        const animateEl = document.getElementById('animate');
        const animate  = new mdb.Animate(manuallyEl, {
          animation: 'fade-in',
          animationStart: 'manually',
        });
        animate.startAnimation();
      
        
    

Customize animation via CSS class

Name Description
infinite Set infinite animation
delay-1s Set animation delay to delay-1s
delay-2s Set animation delay to delay-2s
delay-3s Set animation delay to delay-3s
delay-4s Set animation delay to delay-4s
delay-5s Set animation delay to delay-5s
fast Set animation duration to 800ms
faster Set animation duration to 500ms
slow Set animation duration to 2s
slower Set animation duration to 3s

Callbacks

Name Description
onStart This callback fires before the animation starts.
onEnd This callback starts immediately after the animation has finished.
onShow If you use animate on scroll this callback will start when the element appears on the screen.
onHide If you use animate on scroll this callback will start after the element disappears from the screen.
        
            
        const animateEl = document.getElementById('animate');
        const animate  = new mdb.Animate(manuallyEl, {
          animation: 'fade-in',
          onStart: () => {
            // do something.
          }
        });
        animate.init();