Quick Reference
The @keyframes rule defines the animation timeline, which gradually changes from one set of CSS styles to another.
The @keyframes rules specifies when the style changes will happen in percent, or with the keywords “from” and “to”, which is the same as 0% and 100%. 0% is the beginning of the animation, 100% is when the animation has completed.
Moving an Element
@keyframes my_animation {
from {
top: 0px;
}
to {
top: 500px;
}
}
@keyframes my_animation {
0% {
top: 0px;
}
25% {
top: 500px;
}
50% {
top: 250px;
}
75% {
top: 500px;
}
100% {
top: 0px;
}
}
Changing Multiple CSS Values
@keyframes my_animation {
from {
top: 0px;
background: red;
}
to {
top: 500px;
background: blue;
}
}
Note
The !important rule cannot be used in an @keyframes animation.
Values
These are the allowed values.
Value | Description |
---|---|
animationname | Defines the name of the animation (required) |
keyframes-selector | Percentage of the animation duration (required)
|
css-styles | One or more legal CSS style properties (required) |
CSS Notes:
- The “inherit”, “initial” and “unset” keywords can be used with any CSS property to set its value
- In CSS there are many ways to express a color value in a property
We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.