Hover effects

React Bootstrap 5 Hover effects component

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 rippleColor.

        
            
            import React from 'react';
            import { MDBRipple } from 'mdb-react-ui-kit';
    
            export default function App() {
              return (
                <MDBRipple
                  className='bg-image hover-overlay shadow-1-strong rounded'
                  rippleTag='div'
                  rippleColor='light'
                >
                  <img src='https://mdbootstrap.com/img/new/fluid/city/113.webp' className='w-100' />
                  <a href='#!'>
                    <div className='mask' style={{ backgroundColor: 'rgba(251, 251, 251, 0.2)' }}></div>
                  </a>
                </MDBRipple>
              );
            }
          
        
    

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.

        
            
              import React from 'react';
      
              export default function App() {
                return (
                  <div className='bg-image hover-overlay'>
                    <img src='https://mdbootstrap.com/img/new/standard/city/053.webp' className='w-100' />
                    <div
                      className='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.

        
            
              import React from 'react';
      
              export default function App() {
                return (
                  <div className='bg-image hover-zoom'>
                    <img src='https://mdbootstrap.com/img/new/standard/city/053.webp' className='w-100' />
                  </div>
                );
              }
            
        
    

Shadow

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

        
            
              import React from 'react';
      
              export default function App() {
                return (
                  <img
                    src='https://mdbootstrap.com/img/new/standard/city/041.webp'
                    className='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.

        
            
            import React from 'react';
            import { MDBRipple } from 'mdb-react-ui-kit';
    
            export default function App() {
              return (
                <MDBRipple rippleTag='div' className='bg-image hover-overlay hover-zoom hover-shadow'>
                  <img src='https://mdbootstrap.com/img/new/fluid/city/113.webp' className='w-100' />
                  <a href='#!'>
                    <div className='mask' style={{ backgroundColor: 'rgba(57, 192, 237, 0.2)' }}></div>
                  </a>
                </MDBRipple>
              );
            }
          
        
    

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.

        
            
            import React from 'react';
            import { MDBRipple } from 'mdb-react-ui-kit';
    
            export default function App() {
              return (
                <MDBRipple className='bg-image' rippleTag='div' rippleColor='light'>
                  <img src='https://mdbootstrap.com/img/new/standard/city/053.webp' className='w-100' />
                  <a href='#!'>
                    <div className='mask' style={{ backgroundColor: 'rgba(0, 0, 0, 0.4)' }}>
                      <div className='d-flex justify-content-center align-items-center h-100'>
                        <p className='text-white mb-0'>Can you see me?</p>
                      </div>
                    </div>
                    <div className='hover-overlay'>
                      <div className='mask' style={{ backgroundColor: 'rgba(251, 251, 251, 0.2)' }}></div>
                    </div>
                  </a>
                </MDBRipple>
              );
            }
          
        
    

CSS variables

        
            
          // .hover-overlay
          --#{$prefix}image-hover-transition: #{$image-hover-overlay-transition};

          // .hover-zoom
          --#{$prefix}image-hover-zoom-transition: #{$image-hover-zoom-transition};
          --#{$prefix}image-hover-zoom-transform: #{$image-hover-zoom-transform};
        
          // .hover-shadow
          --#{$prefix}image-hover-shadow-transition: #{$image-hover-shadow-transition};
          --#{$prefix}image-hover-shadow-box-shadow: #{$image-hover-shadow-box-shadow};

          // .hover-shadow-soft
          --#{$prefix}image-hover-shadow-box-shadow-soft: #{$image-hover-shadow-box-shadow-soft};
        
        
    

SCSS variables

        
            
        $image-hover-overlay-transition: all 0.3s ease-in-out;

        $image-hover-zoom-transition: all 0.3s linear;
        $image-hover-zoom-transform: scale(1.1);
        
        $image-hover-shadow-transition: $image-hover-overlay-transition;
        $image-hover-shadow-box-shadow: $box-shadow-4-strong;
        $image-hover-shadow-box-shadow-soft: $box-shadow-5;