CSS Reference

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.

ValueDescription
animationnameDefines the name of the animation (required)
keyframes-selectorPercentage of the animation duration (required)
  • 0-100%
  • from (same as 0%)
  • to (same as 100%)
css-stylesOne or more legal CSS style properties (required)

CSS Notes:


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.