CSS Loading Spinner Example

CSS Loading Spinner Example

This is a loading spinner made with HTML and CSS and animation effects. You can download the source code for free below.

The logic is simple. There is a div element with class loading. I set the border-radius to 50%. I added border-top-color and border-bottom-color. The animation is set with transform property. Initially, it is rotate(0deg), and the final value is rotate(360deg).


Final output:

If the video isn’t working, watch it on the YouTube.

Helpful links to understand the code:

Here is the source code:

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Loading Spinner</title>

      * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;

      .loading {
        width: 4rem;
        height: 4rem;
        border: 0.2em solid transparent;
        border-top-color: rgb(255, 46, 84);
        border-bottom-color: rgb(255, 46, 84);
        border-radius: 50%;
        animation: rotate-animation 0.8s linear infinite;

        /* Center the div */
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        position: absolute;
        margin: auto;

      @keyframes rotate-animation {
        0% {
          transform: rotate(0deg);
        100% {
          transform: rotate(360deg);
    <div class="loading"></div>

Leave a Comment