How to Create CSS Keyframe Animations (Step by Step)
CSS @keyframes animations let you define multi-step sequences that go far beyond simple transitions. While transitions animate between two states, keyframe animations can define any number of intermediate steps โ entrance effects, loading sequences, attention-grabbers, and complex choreographed motion.
- Build CSS @keyframes animations from scratch.
- Covers @keyframes basics.
- Covers multi-step animations.
- Covers animation properties deep dive.
- Covers using the css animation generator.
@keyframes Basics
Define an animation with @keyframes and apply it with the animation property:
@keyframes fadeIn {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
.element {
animation: fadeIn 0.5s ease-out forwards;
}
'from' equals 0%, 'to' equals 100%. The animation shorthand combines name, duration, easing, delay, iteration-count, direction, fill-mode, and play-state.
Multi-Step Animations
Use percentage keyframes for intermediate steps:
transform and opacity for smooth 60fps performance. These properties are handled by the GPU compositor and skip expensive layout recalculations.@keyframes bounce {
0% { transform: translateY(0); }
40% { transform: translateY(-30px); }
60% { transform: translateY(-15px); }
80% { transform: translateY(-5px); }
100% { transform: translateY(0); }
}
Each percentage defines a state at that point in the timeline. The browser interpolates between them using the specified easing function.
Animation Properties Deep Dive
animation-fill-mode: forwards keeps the element at the final keyframe state after the animation ends. Without it, elements snap back to their pre-animation state. animation-delay staggers multiple elements: apply increasing delays to child elements for a cascading entrance effect. animation-iteration-count: infinite loops forever โ use for loading indicators and ambient effects. animation-direction: alternate reverses on even iterations โ creates a ping-pong effect.
width, height, top, or left. These trigger layout recalculations on every frame and can drop performance below 60fps.Using the CSS Animation Generator
The CSS Animation Generator provides preset animations (fade, slide, bounce, rotate, scale, shake) that you can customize with duration, easing, delay, and iteration settings. Preview the animation in real time, adjust parameters until it feels right, then copy the complete CSS including the @keyframes block. Much faster than writing keyframes by hand.
Frequently Asked Questions
How do I create a CSS animation?
What is animation-fill-mode: forwards?
How do I loop a CSS animation?
Use the CSS Animation Generator โ free, no signup required.
โก Open CSS Animation Generator