Discover and download high-quality CSS animations to enhance your website's design.
Keyframes in CSS allow you to define intermediary steps for animations, enabling smooth transitions between multiple states. By specifying styles at certain points (percentages) within the animation's duration, you can create complex animations.
@keyframes example {
0% { transform: rotate(0deg); }
50% { transform: rotate(180deg); }
100% { transform: rotate(360deg); }
}
After defining keyframes, use the animation
property to apply them to an element.
div {
animation: example 2s ease-in-out infinite;
}
The animation
shorthand consists of the following properties:
Property | Description |
---|---|
animation-name | The name of the keyframes block. |
animation-duration | How long the animation takes (e.g., 2s ). |
animation-timing-function | Controls the speed curve (e.g., ease-in ). |
animation-delay | Delay before starting the animation. |
animation-iteration-count | Number of times to play (or infinite ). |
animation-direction | Normal, reverse, alternate, etc. |
animation-fill-mode | Determines the styles before and after the animation runs. |
animation-play-state | Running or paused. |
Here is an example using all animation properties:
@keyframes exampleAnimation {
0% { transform: translateX(0); opacity: 0; }
50% { transform: translateX(100px); opacity: 0.5; }
100% { transform: translateX(200px); opacity: 1; }
}
div {
animation: exampleAnimation 2s ease-in-out 1s infinite alternate forwards;
/* animation-name: exampleAnimation;
animation-duration: 2s;
animation-timing-function: ease-in-out;
animation-delay: 1s;
animation-iteration-count: infinite;
animation-direction: alternate;
animation-fill-mode: forwards; */
}
Here are some common settings for CSS animations:
Category | Values |
---|---|
Timing Functions | ease , linear , ease-in , ease-out , ease-in-out , and custom cubic-bezier values. |
Directions | normal (default), reverse , alternate , alternate-reverse . |
Fill Modes | none , forwards , backwards , both . |
Loading blogs...