How to Create a Stylish Rotating Loader Animation with HTML and CSS

Creating visually appealing animations is a fantastic way to enhance the user experience on your website. One of the most useful animations is a loader, which informs users that content is being loaded. In this article, we’ll guide you through the process of creating a stylish rotating loader animation using HTML and CSS. This loader is not only functional but also adds a modern and professional touch to your site.

YouTube video

Why Use a Loader Animation?

Loader animations are essential for providing visual feedback to users, especially when they have to wait for content to load. A well-designed loader can keep users engaged, reduce perceived waiting time, and improve the overall user experience. Our rotating loader animation is simple yet elegant, making it a perfect addition to any website.

Steps to Create a Rotating Loader Animation

1. Setting Up the HTML Structure

To start, you’ll need a basic HTML structure. This structure will include a container for the loader animation.

2. Styling with CSS

The next step is to style the loader using CSS. We’ll use CSS properties like border-radius, animation, and transform to create the rotating effect. These properties will ensure that our loader is not only functional but also visually appealing.

3. Adding Animation

Animations in CSS are created using the @keyframes rule. This allows you to define a sequence of styles that will be applied to the loader at different points in time, creating a smooth rotating effect.

Benefits of Using CSS for Animations

CSS animations are lightweight and do not require JavaScript, making them faster and more efficient. They are also supported by all modern browsers, ensuring that your loader animation will work seamlessly for all users.

Conclusion

Creating a stylish rotating loader animation with HTML and CSS is a straightforward process that can significantly enhance the user experience on your website. This guide provides you with the steps to achieve this, ensuring that your site remains engaging and professional.

You can copy the code below to implement this rotating loader animation on your own website. Experiment with different styles and animations to make it unique to your brand.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Loader Animation</title>
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Bebas+Neue&display=swap');

        html, body {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 100vw;
            height: 100vh;
            background-color: #321232;
            margin: 0;
        }

        .loader {
            width: 100px;
            height: 100px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            position: relative;
        }

        .section {
            width: 5px;
            height: 10px;
            background-color: rgba(255, 255, 255, .075);
            border-radius: 2px;
            position: absolute;
            animation: rotate 2.5s ease infinite;
            animation-fill-mode: forwards;
        }

        @keyframes rotate {
            from {
                background-color: #F09;
            }
            to {
                background-color: rgba(255, 255, 255, .075);
            }
        }

        .path {
            position: absolute;
            font-size: 32px;
            font-family: 'Bebas Neue';
            width: 275px;
            height: 275px;
            fill: white;
        }

        .holder {
            height: 75px;
            width: 0;
            position: absolute;
            animation: rotatet 8s linear infinite;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        @keyframes rotatet {
            to {
                transform: rotate(360deg);
            }
        }

        .p1, .p2, .p3, .p4, .p5, .p6, .p7 {
            color: #fff;
            position: absolute;
            font-family: 'Bebas Neue';
            font-size: 24px;
        }
    </style>
</head>
<body>
    <div class="loader">
        <script>
            for (let index = 0; index < 45; index++) {
                const section = document.createElement('div');
                section.className = `section section${index}`;
                section.style.transform = `rotate(${8 * index}deg) translate(0, -45px)`;
                section.style.animationDelay = `${.055 * index}s`;
                document.querySelector('.loader').appendChild(section);
            }
        </script>
    </div>
    <div class="holder">
        <script>
            const letters = ['G', 'N', 'I', 'D', 'A', 'O', 'L'];
            letters.forEach((letter, idx) => {
                const p = document.createElement('p');
                p.className = `p${idx + 1}`;
                p.innerText = letter;
                p.style.transform = `rotate(${-360 / 12 * (idx + 1)}deg) translate(0, -65px)`;
                document.querySelector('.holder').appendChild(p);
            });
        </script>
    </div>
</body>
</html>

By following these steps, you’ll have a fully functional and stylish loader animation that will impress your site visitors and keep them engaged. Happy coding!

Feel free to copy the code provided below and try it out on your own projects. This simple yet effective loader animation will make your website stand out and provide a better user experience.

Leave a Comment

Item added to cart.
0 items - $0.00