Open In App

How to Create Circle Loading Animation Effect using CSS ?

In this article, we will see how to create a circle-loading animation using HTML and CSS, along with understanding its basic implementation through the example. Generally, Loading Animation is utilized to wait for the content to be fully loaded on the webpage. If some pages don’t contain the loader, then the user may think that the webpage is not responding at all. By adding the loader may distract or wait for a few seconds until the page is fully loaded.

Approach: The below approach will be utilized to create the simple circle-loading animation:



Step 1: Adding HTML

First, we create a div element with the class “loader”. This div element contains another div element with the class “loader-inner”. Once we have the container element in place, we can begin creating the actual animation. 






<div class="loader">
    <div class="loader-inner"></div>
</div>

Step 2: Adding CSS




.loader {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80px;
    height: 80px;
 }




.loader-inner {
    position: absolute;
    top: 0;
    left: 0;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-top-color: #5CDB95;
}




.loader-inner::before {
    content: "";
    position: absolute;
    top: 12px;
    left: 12px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: url(
          no-repeat center center;
    background-size: 100%;
}




@keyframes loader-animation {
    0% {
        transform: rotate(0deg);
    }
  
    100% {
        transform: rotate(360deg);
    }
}
  
.loader-inner::before {
  
    /* Other CSS properties */
    animation: loader-animation 2s infinite ease-in-out;
}
  
@keyframes loader-spin {
    to {
        transform: rotate(360deg);
    }
}
  
.loader-inner {
  
    /* Other CSS properties */
    animation: loader-spin 1.5s linear infinite;
}

Example: This example describes the creation of a circle-loading animation using HTML and CSS.




<!DOCTYPE html>
<html>
  
<head>
    <meta charset="utf-8">
    <meta name="viewport" 
          content="width=device-width">
    <style>
        .loader {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 80px;
            height: 80px;
        }
  
        .loader-inner {
            position: absolute;
            top: 0;
            left: 0;
            width: 80px;
            height: 80px;
            border-radius: 50%;
            border: 4px solid rgba(0, 0, 0, 0.1);
            border-top-color: #5CDB95;
            background-image: 
              linear-gradient(to right, #5CDB95, #8EE4AF, #ADD5A7);
            animation: loader-spin 1.5s linear infinite;
        }
  
        .loader-inner::before {
            content: "";
            position: absolute;
            top: 12px;
            left: 12px;
            width: 56px;
            height: 56px;
            border-radius: 50%;
            background: url(
                no-repeat center center;
            background-size: 100%;
            animation: loader-animation 2s infinite ease-in-out;
        }
  
        @keyframes loader-animation {
            0% {
                transform: rotate(0deg);
            }
  
            100% {
                transform: rotate(360deg);
            }
        }
  
        @keyframes loader-spin {
            to {
                transform: rotate(360deg);
            }
        }
    </style>
  
</head>
  
<body>
    <div class="loader">
        <div class="loader-inner"></div>
    </div>
</body>
  
</html>

Output:

circle-loading animation


Article Tags :