How to Create Hover Animation On Button Using HTML/CSS?

 Hello Guys ,

      In this tutorial we are create hover animation on button using html and css. It displays the emoji when the cursor moves over the button. Here we will use the fontawesome CDN Link  for emoji.

                     https://kit.fontawesome.com/704ff50790.js

Please place above link in the script tag.

Hover animation on button looking like below picture:



Let's get started.

HTML CODE :

  • Create html file.
  • Create Structure for all button that will be a switch to icon.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
    <div class="container">
      <div class="button-effect">
         <h2>Animated Buttons</h2>
          <a class="button effect-4" href="#"
           title="Delivery">Delivery </a>

          <a class="button effect-3" href="#"
           title="Download">Download </a>

          <a class="button effect-2" href="#"
            title="Upload">Upload </a>

          <a class="button effect-1" href="#"
            title="Delete">Delete </a>

    
       </div>
    </div>

    <script src=
"https://kit.fontawesome.com/704ff50790.js"></script>

</body>
</html>

CSS CODE :

  • Here we can set background color , set margin and alignment text for body using below code.
/* Here we can set background color */  
    body {
        background-colorwhite;
    }
    
    /* set margin and alignment for text */
    body .container {
        width850px;
        margin70px auto 0px;
        text-aligncenter;
    }

  • Here we can set font-family , font-size , color and style for h2 tag using below code.
  • h2 tag is used for heading or text.
body .container .button-effect {
        padding30px 0px;
    }


    body .container .button-effect h2 {
        font-family"Droid Serif"serif;
        font-size40px;
        colorblack;
        text-decoration-stylebold;
        margin-bottom70px;
    }

  • Here we can set background color for specific button using below code.
body .container .button-effect a {
        margin-right17px;
    }
    /* here you can set background color for specific button */
    body .container .button-effect a:nth-child(2) {
        background-colorwhite;
    }

    /* here you can set background color for specific button */
    body .container .button-effect a:nth-child(3) {
        background-colorwhite;
    }

    /* here you can set background color for specific button */
    body .container .button-effect a:nth-child(4) {
        background-colorwhite;
    }

    /* here you can set background color for specific button */
    body .container .button-effect a:nth-child(5) {
        background-colorwhite;
    }
 
  • Here we can set text-align , text-decoration , position , font-family , font-size , padding for button using below code.
.button {
        text-aligncenter;
        displayinline-block;
        positionrelative;
        text-decorationnone;
        colorblack;
        text-transformcapitalize;
        /* background-color: - add your own background-color */
        font-family"Roboto"sans-serif;

        /* put your font-family */
        font-size18px;
        padding20px 0px;
        width150px;
        border-radius6px;
        overflowhidden;
    }

  • Here we can set effect for every button using below code.
/*Effect for Delivery Button
       Here you can set time for transition 
    */
    .button.effect-4 {
        transitionall 0.2s linear 0s;
    }
    .button.effect-4:before {
        content"\f0d1";
        font-family: FontAwesome;
        displayflex;
        align-itemscenter;
        justify-contentcenter;
        positionabsolute;
        top0;
        left0px;
        width100%;
        height100%;
        text-aligncenter;
        font-size30px;
        transformscale(01);
        transitionall 0.2s linear 0s;
    }
    .button.effect-4:hover {
        text-indent-9999px;
    }
    .button.effect-4:hover:before {
        transformscale(11);
        text-indent0;
    }

    /*Effect for Download Button
       Here you can set time for transition 
    */
    .button.effect-3 {
        transitionall 0.2s linear 0s;
    }
    .button.effect-3:before {
        content"\f019";
        font-family: FontAwesome;
        displayflex;
        align-itemscenter;
        justify-contentcenter;
        positionabsolute;
        top0;
        left0px;
        width100%;
        height100%;
        text-aligncenter;
        font-size30px;
        transformscale(01);
        transitionall 0.2s linear 0s;
    }
    .button.effect-3:hover {
        text-indent-9999px;
    }
    .button.effect-3:hover:before {
        transformscale(11);
        text-indent0;
    }


    /*Effect for Upload Button
       Here you can set time for transition 
    */
    .button.effect-2 {
        transitionall 0.2s linear 0s;
    }
    .button.effect-2:before {
        content"\f093";
        font-family: FontAwesome;
        displayflex;
        align-itemscenter;
        justify-contentcenter;
        positionabsolute;
        top0;
        left0px;
        width100%;
        height100%;
        text-aligncenter;
        font-size30px;
        transformscale(01);
        transitionall 0.2s linear 0s;
    }
    .button.effect-2:hover {
        text-indent-9999px;
    }
    .button.effect-2:hover:before {
        transformscale(11);
        text-indent0;
    }

    /*Effect for Delete Button
       Here you can set time for transition 
    */
    .button.effect-1 {
        transitionall 0.2s linear 0s;
    }
    .button.effect-1:before {
        content"\f2ed";
        font-family: FontAwesome;
        displayflex;
        align-itemscenter;
        justify-contentcenter;
        positionabsolute;
        top0;
        left0px;
        width100%;
        height100%;
        text-aligncenter;
        font-size30px;
        transformscale(01);
        transitionall 0.2s linear 0s;
    }
    .button.effect-1:hover {
        text-indent-9999px;
    }
    .button.effect-1:hover:before {
        transformscale(11);
        text-indent0;
    }


Complete CSS CODE :
  • we can create css file and link to the html file but here we write the code using style tags in the head tag.
<style>

    /* Here we can set background color */  
    body {
        background-colorwhite;
    }
    
    /* set margin and alignment for text */
    body .container {
        width850px;
        margin70px auto 0px;
        text-aligncenter;
    }


    body .container .button-effect {
        padding30px 0px;
    }


    body .container .button-effect h2 {
        font-family"Droid Serif"serif;
        font-size40px;
        colorblack;
        text-decoration-stylebold;
        margin-bottom70px;
    }
    body .container .button-effect a {
        margin-right17px;
    }
    /* here you can set background color for specific button */
    body .container .button-effect a:nth-child(2) {
        background-colorwhite;
    }

    /* here you can set background color for specific button */
    body .container .button-effect a:nth-child(3) {
        background-colorwhite;
    }

    /* here you can set background color for specific button */
    body .container .button-effect a:nth-child(4) {
        background-colorwhite;
    }

    /* here you can set background color for specific button */
    body .container .button-effect a:nth-child(5) {
        background-colorwhite;
    }
    
  
  
    .button {
        text-aligncenter;
        displayinline-block;
        positionrelative;
        text-decorationnone;
        colorblack;
        text-transformcapitalize;
        /* background-color: - add your own background-color */
        font-family"Roboto"sans-serif;

        /* put your font-family */
        font-size18px;
        padding20px 0px;
        width150px;
        border-radius6px;
        overflowhidden;
    }

    /*Effect for Delivery Button
       Here you can set time for transition 
    */
    .button.effect-4 {
        transitionall 0.2s linear 0s;
    }
    .button.effect-4:before {
        content"\f0d1";
        font-family: FontAwesome;
        displayflex;
        align-itemscenter;
        justify-contentcenter;
        positionabsolute;
        top0;
        left0px;
        width100%;
        height100%;
        text-aligncenter;
        font-size30px;
        transformscale(01);
        transitionall 0.2s linear 0s;
    }
    .button.effect-4:hover {
        text-indent-9999px;
    }
    .button.effect-4:hover:before {
        transformscale(11);
        text-indent0;
    }

    /*Effect for Download Button
       Here you can set time for transition 
    */
    .button.effect-3 {
        transitionall 0.2s linear 0s;
    }
    .button.effect-3:before {
        content"\f019";
        font-family: FontAwesome;
        displayflex;
        align-itemscenter;
        justify-contentcenter;
        positionabsolute;
        top0;
        left0px;
        width100%;
        height100%;
        text-aligncenter;
        font-size30px;
        transformscale(01);
        transitionall 0.2s linear 0s;
    }
    .button.effect-3:hover {
        text-indent-9999px;
    }
    .button.effect-3:hover:before {
        transformscale(11);
        text-indent0;
    }


    /*Effect for Upload Button
       Here you can set time for transition 
    */
    .button.effect-2 {
        transitionall 0.2s linear 0s;
    }
    .button.effect-2:before {
        content"\f093";
        font-family: FontAwesome;
        displayflex;
        align-itemscenter;
        justify-contentcenter;
        positionabsolute;
        top0;
        left0px;
        width100%;
        height100%;
        text-aligncenter;
        font-size30px;
        transformscale(01);
        transitionall 0.2s linear 0s;
    }
    .button.effect-2:hover {
        text-indent-9999px;
    }
    .button.effect-2:hover:before {
        transformscale(11);
        text-indent0;
    }

    /*Effect for Delete Button
       Here you can set time for transition 
    */
    .button.effect-1 {
        transitionall 0.2s linear 0s;
    }
    .button.effect-1:before {
        content"\f2ed";
        font-family: FontAwesome;
        displayflex;
        align-itemscenter;
        justify-contentcenter;
        positionabsolute;
        top0;
        left0px;
        width100%;
        height100%;
        text-aligncenter;
        font-size30px;
        transformscale(01);
        transitionall 0.2s linear 0s;
    }
    .button.effect-1:hover {
        text-indent-9999px;
    }
    .button.effect-1:hover:before {
        transformscale(11);
        text-indent0;
    }

    
</style>


Complete CODE :
<!DOCTYPE html>
<html>
<head>
    
    <style>

    /* Here we can set background color */  
    body {
        background-colorwhite;
    }
    
    /* set margin and alignment for text */
    body .container {
        width850px;
        margin70px auto 0px;
        text-aligncenter;
    }


    body .container .button-effect {
        padding30px 0px;
    }


    body .container .button-effect h2 {
        font-family"Droid Serif"serif;
        font-size40px;
        colorblack;
        text-decoration-stylebold;
        margin-bottom70px;
    }
    body .container .button-effect a {
        margin-right17px;
    }
    /* here you can set background color for specific button */
    body .container .button-effect a:nth-child(2) {
        background-colorwhite;
    }

    /* here you can set background color for specific button */
    body .container .button-effect a:nth-child(3) {
        background-colorwhite;
    }

    /* here you can set background color for specific button */
    body .container .button-effect a:nth-child(4) {
        background-colorwhite;
    }

    /* here you can set background color for specific button */
    body .container .button-effect a:nth-child(5) {
        background-colorwhite;
    }
    
  
  
    .button {
        text-aligncenter;
        displayinline-block;
        positionrelative;
        text-decorationnone;
        colorblack;
        text-transformcapitalize;
        /* background-color: - add your own background-color */
        font-family"Roboto"sans-serif;

        /* put your font-family */
        font-size18px;
        padding20px 0px;
        width150px;
        border-radius6px;
        overflowhidden;
    }

    /*Effect for Delivery Button
       Here you can set time for transition 
    */
    .button.effect-4 {
        transitionall 0.2s linear 0s;
    }
    .button.effect-4:before {
        content"\f0d1";
        font-family: FontAwesome;
        displayflex;
        align-itemscenter;
        justify-contentcenter;
        positionabsolute;
        top0;
        left0px;
        width100%;
        height100%;
        text-aligncenter;
        font-size30px;
        transformscale(01);
        transitionall 0.2s linear 0s;
    }
    .button.effect-4:hover {
        text-indent-9999px;
    }
    .button.effect-4:hover:before {
        transformscale(11);
        text-indent0;
    }

    /*Effect for Download Button
       Here you can set time for transition 
    */
    .button.effect-3 {
        transitionall 0.2s linear 0s;
    }
    .button.effect-3:before {
        content"\f019";
        font-family: FontAwesome;
        displayflex;
        align-itemscenter;
        justify-contentcenter;
        positionabsolute;
        top0;
        left0px;
        width100%;
        height100%;
        text-aligncenter;
        font-size30px;
        transformscale(01);
        transitionall 0.2s linear 0s;
    }
    .button.effect-3:hover {
        text-indent-9999px;
    }
    .button.effect-3:hover:before {
        transformscale(11);
        text-indent0;
    }


    /*Effect for Upload Button
       Here you can set time for transition 
    */
    .button.effect-2 {
        transitionall 0.2s linear 0s;
    }
    .button.effect-2:before {
        content"\f093";
        font-family: FontAwesome;
        displayflex;
        align-itemscenter;
        justify-contentcenter;
        positionabsolute;
        top0;
        left0px;
        width100%;
        height100%;
        text-aligncenter;
        font-size30px;
        transformscale(01);
        transitionall 0.2s linear 0s;
    }
    .button.effect-2:hover {
        text-indent-9999px;
    }
    .button.effect-2:hover:before {
        transformscale(11);
        text-indent0;
    }

    /*Effect for Delete Button
       Here you can set time for transition 
    */
    .button.effect-1 {
        transitionall 0.2s linear 0s;
    }
    .button.effect-1:before {
        content"\f2ed";
        font-family: FontAwesome;
        displayflex;
        align-itemscenter;
        justify-contentcenter;
        positionabsolute;
        top0;
        left0px;
        width100%;
        height100%;
        text-aligncenter;
        font-size30px;
        transformscale(01);
        transitionall 0.2s linear 0s;
    }
    .button.effect-1:hover {
        text-indent-9999px;
    }
    .button.effect-1:hover:before {
        transformscale(11);
        text-indent0;
    }

    
    </style>
</head>
<body>
    <div class="container">
      <div class="button-effect">
         <h2>Animated Buttons</h2>
          <a class="button effect-4" href="#"
           title="Delivery">
             Delivery
          </a>

          <a class="button effect-3" href="#"
           title="Download">Download</a>

          <a class="button effect-2" href="#"
            title="Upload">Upload</a>

          <a class="button effect-1" href="#"
            title="Delete">Delete</a>

    
       </div>
    </div>

    <script src=
"https://kit.fontawesome.com/704ff50790.js"></script>

</body>
</html>


Output :





If you liked this post do comment ,share and promote the post 🙏 . Please stay with us and support.  🙏




  

Post a Comment

0 Comments