To create a CSS animation that rotates an element continuously, you can use the @keyframes
rule along with the transform
property. Here's a simple example:
html<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
@keyframes rotate {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.rotate-element {
width: 100px;
height: 100px;
background-color: #3498db;
animation: rotate 5s linear infinite; /* 5s duration, linear easing, infinite loop */
}
</style>
</head>
<body>
<div class="rotate-element"></div>
</body>
</html>
In this example:
We define a @keyframes
rule named rotate
with two keyframes: 0%
and 100%
. The transform
property is used to specify the rotation at each keyframe.
We create a class .rotate-element
for the element you want to rotate. In this case, it's a simple square div with a blue background.
The animation
property is applied to the .rotate-element
class, specifying the name of the keyframes (rotate
), the duration of the animation (5s
), the timing function (linear
for a constant speed), and infinite
to make it loop continuously.
Adjust the properties according to your requirements. You can change the duration, easing function, and other animation properties as needed.