What You'll Learn
You'll discover how to create sophisticated, multi-step animations in CSS using the @keyframes rule to define exactly what happens at each stage of your animation.
Beyond Simple Transitions
So far, you've learned how CSS transitions smoothly animate changes between two states (like hover effects). But what if you want an element to move through multiple stages—first rotating, then changing color, then scaling up? That's where @keyframes comes in.
Think of @keyframes as creating a choreographed dance routine rather than just a simple move from point A to point B. You define specific "poses" (keyframes) at different moments in time, and the browser smoothly fills in the movements between them.
The Basic Structure
The @keyframes rule lets you create a named animation timeline. You give it a name and define what CSS properties should look like at different points during the animation:
@keyframes slideFade {
0% {
opacity: 0;
transform: translateX(-100px);
}
50% {
opacity: 1;
}
100% {
opacity: 1;
transform: translateX(0);
}
}
The percentages represent how far through the animation you are. 0% is the start, 100% is the end, and you can add as many steps in between as you need. You can also use the keywords from (same as 0%) and to (same as 100%).
Once defined, this animation doesn't run automatically—it's like saving a recipe. You'll apply it to elements in future lessons, but for now, understand that @keyframes is purely about defining the sequence.
Why It Matters
This separation of definition and application is powerful: you can create one animation and reuse it across many elements, each potentially with different durations or timing functions.
Key Takeaway: The @keyframes rule creates a named animation sequence by defining CSS property values at specific percentage points along a timeline, giving you precise control over multi-step animations.