Hover effects

Bootstrap 5 Hover effects

MDB hover effect appears when the user positions the computer cursor over an element without activating it. Hover effects make a website more interactive.

However, we don't recommend that you mix hover effects with functional elements (like a drop-down on hover or hidden buttons visible only after hovering) because such an approach isn't mobile-friendly.

MDB is a mobile-first framework, so we attach great importance to making each component easy to use for touch screens.

That's why our hover effects are gentle and decorative.


Basic example

Here is the most common example of hover effects usage - an image changed to link with an additional ripple effect on click.

Additionally, we added shadows and rounded corners and also changed ripple color to light via data-mdb-attribute.


          <div
            class="bg-image hover-overlay ripple shadow-1-strong rounded"
            data-mdb-ripple-color="light"
          >
            <img src="https://mdbootstrap.com/img/new/fluid/city/113.webp" class="w-100" />
            <a href="#!">
              <div class="mask" style="background-color: rgba(251, 251, 251, 0.2)"></div>
            </a>
          </div>
        

Types

In MDB there are 3 types of the hover effects: overlay, zoom and shadow.

Overlay

Overlay is an effect that covers with color and defined level of opacity the entire image. The same as with mask you can change the color and opacity by manipulating RGBA code.

Our overlay hover effect relies on masks. Have a look at our masks docs to learn more.

Add .overlay class to the .mask element to apply hover effect. Then manipulate RGBA code to change the color of the overlay.

rgba(18, 102, 241, 0.5)
rgba(178, 60, 253, 0.2)
rgba(0, 183, 74, 0.78)
rgba(249, 49, 84, 0.34)
rgba(251, 251, 251, 0.35)
rgba(57, 192, 237, 0.3)

You can even set a fancy gradient as an overlay.


            <div class="bg-image hover-overlay">
              <img src="https://mdbootstrap.com/img/new/standard/city/053.webp" class="w-100" />
              <div
                class="mask"
                style="
                  background: linear-gradient(
                    45deg,
                    rgba(29, 236, 197, 0.5),
                    rgba(91, 14, 214, 0.5) 100%
                  );
                "
              ></div>
            </div>
          

Zoom

To apply zoom hover effect you have to use slightly different, but simpler syntax.

You only need to add .hover-zoom class to the .bg-image element.


            <div class="bg-image hover-zoom">
              <img src="https://mdbootstrap.com/img/new/standard/city/053.webp" class="w-100" />
            </div>
          

Shadow

Shadow hover effect is even simpler. Simply add .hover-shadow class to any element to apply the effect.


            <img
              src="https://mdbootstrap.com/img/new/standard/city/041.webp"
              class="w-100 hover-shadow"
              alt=""
            />
          

Mixing effects

You can freely mix all the effects with each other. However, be careful not to overdo it. MDB adheres to the principle of minimalism and subtlety.


          <div class="bg-image hover-overlay hover-zoom hover-shadow ripple">
            <img src="https://mdbootstrap.com/img/new/fluid/city/113.webp" class="w-100" />
            <a href="#!">
              <div class="mask" style="background-color: rgba(57, 192, 237, 0.2)"></div>
            </a>
          </div>
        

Overlay over mask

If you want to put a text on the image and you need a proper contrast, but still you wish to have hover effect, you can apply overlay on the already existing mask.


          <div class="bg-image ripple" data-mdb-ripple-color="light">
            <img src="https://mdbootstrap.com/img/new/standard/city/053.webp" class="w-100" />
            <a href="#!">
              <div class="mask" style="background-color: rgba(0, 0, 0, 0.4)">
                <div class="d-flex justify-content-center align-items-center h-100">
                  <p class="text-white mb-0">Can you see me?</p>
                </div>
              </div>
              <div class="hover-overlay">
                <div class="mask" style="background-color: rgba(251, 251, 251, 0.2)"></div>
              </div>
            </a>
          </div>