Open In App

Glassmorphism Card Hover Effect

Glassmorphism is a modern way of styling web-elements of any web-page and providing a 3D as well as a glass effect. This animation effect can be easily generated by using HTML, CSS, and Vanilla-tilt JS. We can implement Glassmorphism using various CSS properties. It is used to add a glass effect to the given element and Vanilla-tilt JS is used to provide a tilt effect to the card.

Installation:



HTML code: In this section, we will make the layout of the card.



index.html




<!DOCTYPE html>
<html>
  
<body>
    <div class="gfg">
        <div class="card">
            <div class="content">
                <h2>GeeksforGeeks</h2>
                <h3>Welcome</h3>
                <p>
                    Learn Data Structures Online At 
                    Your Own Pace With The Best Of 
                    Faculty In The Industry. The Best 
                    Data Structures Course Available
                    Online From Skilled And Experienced 
                    Faculty.
                </p>
            </div>
        </div>
    </div>
</body>
  
</html>

CSS Code: In this section, we will use some CSS properties to design the Card.

index.css




<style>
    *{
        margin:0;
        padding:0;
        box-sizing:border-box;
        
    }
  
    body{
        display:flex;
        justify-content:center;
        align-items:center;
        min-height:100vh;
        background:green;
    }
  
    .gfg{
        position:relative;
        display:flex;
        justify-content:center;
        align-items:center;
        max-width:1000px;
        flex-wrap:wrap;
        z-index:1;
    }
       
    .gfg .card{
        position:relative;
        width:300px;
        height:300px;
        margin:60px;
        box-shadow:20px 20px 50px rgb(0,0,0,0.4);
        border-radius:15px;
        background:rgba(255,255,255,0.1);
        overflow:hidden;
        display:flex;
        justify-content:center;
        align-items:center;
        backdrop-filter:blur(6px);
    }
  
    .gfg .card .content{
        padding:40px;
        text-align:center;
        
    }
</style>

JavaScript Code: In this section, we will use Vanilla-tilt JS to provide a tilt effect to the card.

script.js




<script>
    VanillaTilt.init(document.querySelector(".card"), {
        max: 40,
        speed: 800,
        glare:true,
        "max-glare":2.5,
    });
</script>

Complete Code: In this section, we will combine the above three sections to create a Glassmorphism Effect.




<!DOCTYPE html>
<html>
  
<head>
    <meta charset="utf-8">
    <style>
        *{
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            
        }
  
        body{
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background: green;
        }
  
        .gfg{
            position: relative;
            display: flex;
            justify-content: center;
            align-items: center;
            max-width: 1000px;
            flex-wrap: wrap;
            z-index: 1;
        }
           
        .gfg .card{
            position: relative;
            width: 300px;
            height: 300px;
            margin: 60px;
            box-shadow: 20px 20px 50px rgb(0,0,0,0.4);
            border-radius: 15px;
            background: rgba(255,255,255,0.1);
            overflow: hidden;
            display: flex;
            justify-content: center;
            align-items: center;
            backdrop-filter: blur(6px);
        }
  
        .gfg .card .content{
            padding: 40px;
            text-align: center;
        }
    </style>
</head>
  
<body>
    <div class="gfg">
        <div class="card">
            <div class ="content">
                <h2>GeeksforGeeks</h2>
                <h3>Welcome</h3>
                <p>
                    Learn Data Structures Online At Your 
                    Own Pace With The Best Of Faculty In 
                    The Industry. The Best Data Structures 
                    Course Available Online From Skilled 
                    And Experienced Faculty.
                </p>
            </div>
        </div>
    </div>
    <script src="vanilla-tilt.js">
    </script>
      
    <script>
        VanillaTilt.init(document.querySelector(".card"), {
          max: 40,
          speed: 800,
          glare: true,
          "max-glare": 2.5,
        });
    </script>
</body>
    
</html>

Output:


Article Tags :