CSS Keyframe Animations & fill-mode
Direct complex autonomous motion choreographies. Master @keyframes waypoints, understand why animation-fill-mode: forwards prevents annoying snapping bugs, and create infinite pulsing rings.
1. Mental Model: The Disney Animator's Storyboard
In traditional hand-drawn animation, the lead director sketches the major emotional milestones (the "keyframes" at 0%, 50%, and 100%). Then assistant animators draw all the fluid in-between frames.
Needs user interaction (hover). Moves from point A directly to point B.
Autonomous and multi-stage. Bounce up, squish down, fade out, rotate 360 degrees!
Freeze in mid-air using animation-play-state: paused; on hover.
2. The 4 animation-fill-mode Values Explained
| fill-mode | During Delay (Before Start) | After Finish (After 100%) | Common Use Case |
|---|---|---|---|
| none (Default) | Standard CSS styles apply | Instantly snaps back to base styles! | Continuous looping animations only |
| forwards (Most Used) | Standard CSS styles apply | Freezes at final 100% keyframe forever! | Fade-in entry animations, slide-in banners |
| backwards | Applies 0% keyframe immediately during delay | Snaps back to base styles | Staggered entrance delays |
| both | Applies 0% during delay | Freezes at 100% when finished | Complex delayed choreographies |
3. Interactive Studio: Live Keyframe Director
4. Deep Visualizer: Interactive Keyframe Studio
Animation & Keyframe Lab
Design and inspect real CSS keyframe animations. Tweak timing curves, fill-modes, iterations, and physics live.
Try these
- Change iterations to "1" and test fill-mode: "none" vs "forwards" to see the box stay at 100%!
- Switch timing-function to "steps(4, jump-end)" to see retro 8-bit stepped animation.
- Toggle Play/Pause in mid-flight to freeze and inspect the element’s instantaneous state.
- Switch presets to inspect how real CSS physics like squash-and-stretch are engineered.
💡 forwards maintains the style set by the last keyframe when animation finishes.
First-Year Student Traps: Animations
- 1.The "Snapping Back" Glitch: You animate a modal fading in and translating down. The moment the animation reaches 100%, it vanishes or snaps back to the top of the screen! Solution: Add
animation-fill-mode: forwards;so the browser preserves the final keyframe. - 2.Creating Infinite Loops with Heavy Repaints: If you loop an animation with
box-shadoworfilter: blur(), the browser will burn CPU cycles non-stop, draining mobile batteries in 20 minutes. Keep infinite loops restricted strictly totransformandopacity!
3D Transforms, Perspective & Card Flips
Step into the 3rd dimension with perspective, transform-style: preserve-3d, and backface-visibility.