<!DOCTYPE html>
<html>
<head>
<title>CSS Animations Example</title>
<style>
@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
.box {
width: 100px;
height: 100px;
background-color: #3498db;
animation-name: spin;
animation-duration: 2s;
animation-timing-function: linear;
animation-iteration-count: infinite;
margin: 20px auto;
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
Code Output
CSS Animations
CSS Animations allow you to create dynamic and engaging effects on your web pages. They provide a way to animate CSS properties over a specified duration, with full control over keyframes and timing.
To use CSS Animations, you define a set of keyframes that describe the desired intermediate states of an element during the animation. Each keyframe specifies the CSS properties and their values at a specific point in time. You can control the duration, timing function, delay, and iteration count of the animation.
Syntax
@keyframes animation-name {
from {
/* CSS properties at the start of the animation */
}
to {
/* CSS properties at the end of the animation */
}
/* or */
percentage {
/* CSS properties at a specific percentage of the animation */
}
}
selector {
animation-name: name;
animation-duration: duration;
animation-timing-function: timing-function;
animation-delay: delay;
animation-iteration-count: count;
animation-direction: direction;
animation-fill-mode: fill-mode;
animation-play-state: play-state;
}
-
@keyframes
: Defines a set of keyframes for the animation.animation-name
: Specifies the name of the animation defined by@keyframes
.animation-duration
: Sets the duration of the animation in seconds or milliseconds.animation-timing-function
: Specifies the timing function that controls the animation’s acceleration and deceleration.animation-delay
: Specifies a delay before the animation starts.animation-iteration-count
: Sets the number of times the animation should repeat.animation-direction
: Defines whether the animation should play forward, backward, or alternate between the two.animation-fill-mode
: Specifies how the element should be styled before and after the animation.animation-play-state
: Controls whether the animation is running or paused.