How to Create Animated Loader Ring using HTML and CSS?
Last Updated :
10 Oct, 2024
Improve
An Animated Loader Ring using HTML and CSS is a circular loading animation that visually indicates progress or loading status. It is created with a simple HTML structure and animated using CSS properties like border, transform, and @keyframes for rotation effects.
Approach
- HTML Structure: The code uses a <div> with the class .circle to create the loader ring.
- Body Styling: Sets the background color to green and removes default margins and padding for full coverage.
- Loader Design: The .circle class styles the ring with size, position, border, and circular shape.
- Animation Setup: Uses @keyframes to animate the loader, rotating it from 0 to 360 degrees.
- Infinite Spin: The animation runs infinitely with a 1-second duration and linear timing for smooth rotation.
Example: Here we create an animated loader ring using a <div> styled as a circle. It continuously spins with a 1-second infinite rotation animation, simulating a loading effect on a green background.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>
How to Create Animated Loader
Ring using HTML and CSS?
</title>
<style>
body {
margin: 0;
padding: 0;
background: #008000;
}
.circle {
position: absolute;
top: 40%;
left: 50%;
transform: translate(-40%, -50%);
animation: effect 1s linear infinite;
width: 100px;
height: 100px;
border-radius: 50%;
border: 6px solid rgba(255, 255, 255, 0.3);
border-top-color: #fff;
}
@keyframes effect {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
</style>
</head>
<body>
<div class="circle"></div>
</body>
</html>
Output:
