Skip to content
Back to Concepts
CSS UniverseTrack 8: Transitions & AnimationKeyframe Animations
Transitions & Animation · Track 8Core Concept 31

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.

Transitions (A → B)

Needs user interaction (hover). Moves from point A directly to point B.

Keyframes (A → B → C → D)

Autonomous and multi-stage. Bounce up, squish down, fade out, rotate 360 degrees!

Pause & Resume

Freeze in mid-air using animation-play-state: paused; on hover.

2. The 4 animation-fill-mode Values Explained

fill-modeDuring Delay (Before Start)After Finish (After 100%)Common Use Case
none (Default)Standard CSS styles applyInstantly snaps back to base styles!Continuous looping animations only
forwards (Most Used)Standard CSS styles applyFreezes at final 100% keyframe forever!Fade-in entry animations, slide-in banners
backwardsApplies 0% keyframe immediately during delaySnaps back to base stylesStaggered entrance delays
bothApplies 0% during delayFreezes at 100% when finishedComplex delayed choreographies

3. Interactive Studio: Live Keyframe Director

CSS Animation Code
animation: floatOrb 2s ease-in-out infinite alternate forwards;
animation-play-state: running;
@keyframesforwards

4. Deep Visualizer: Interactive Keyframe Studio

CSS3 Physics Engine

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.
Keeps final 100% state

💡 forwards maintains the style set by the last keyframe when animation finishes.

Preset: Gravity Bounce & Squash
1.4s·infinite·Running
Floor Contact Plane (Impact Zone)
@keyframesGravity
Keyframe Step BreakdownTiming: cubic-bezier(0.34,
0%translateY(-90px) scale(1, 1) [Apex]
45%translateY(0px) scale(1.2, 0.8) [Squash impact]
60%translateY(-35px) scale(0.9, 1.15) [Rebound]
100%translateY(0) scale(1, 1) [Rest]
@keyframes cssviz-bounce { 0% { transform: translateY(-90px) scale(1, 1); } 45% { transform: translateY(0px) scale(1.2, 0.8); /* Squish on impact */ } 60% { transform: translateY(-35px) scale(0.9, 1.15); /* Stretch ascending */ } 80% { transform: translateY(0px) scale(1.05, 0.95); } 100% { transform: translateY(0px) scale(1, 1); } } .animated-element { /* Animation shorthand property */ animation-name: cssviz-bounce; animation-duration: 1.4s; animation-timing-function: cubic-bezier(0.34, 1.56, 0.64, 1); animation-delay: 0s; animation-iteration-count: infinite; animation-direction: normal; animation-fill-mode: forwards; animation-play-state: running; /* Compact 1-line shorthand: */ /* animation: cssviz-bounce 1.4s cubic-bezier(0.34, 1.56, 0.64, 1) infinite normal forwards; */ will-change: transform; }

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-shadow or filter: blur(), the browser will burn CPU cycles non-stop, draining mobile batteries in 20 minutes. Keep infinite loops restricted strictly to transform and opacity!
Next Masterclass

3D Transforms, Perspective & Card Flips

Step into the 3rd dimension with perspective, transform-style: preserve-3d, and backface-visibility.

Continue to Concept 32