The animation-fill-mode property decides what happens to an element’s styles before an animation starts and after it finishes. It helps you avoid elements snapping back to their original look too soon.
01
Before & After
Styles outside active time.
02
Syntax
Four keyword values.
03
none
Default reset behavior.
04
forwards
Keep final keyframe styles.
05
backwards
Apply first keyframe early.
06
both
Combine forwards and backwards.
Fundamentals
Definition and Usage
The animation-fill-mode CSS property defines how computed values from an animation are applied to an element outside the active animation period — that is, before it begins and after it ends.
This is especially useful for entrance animations that should stay visible after finishing, or delayed animations that should already look like their starting keyframe while waiting to begin.
💡
Beginner Tip
If your animated element jumps back to its original position or opacity when the animation ends, try animation-fill-mode: forwards to keep the final keyframe styles.
Foundation
📝 Syntax
Set animation-fill-mode with one of its keyword values:
The initial value is none, so styles outside the animation period are not preserved by default.
forwards keeps the styles from the last keyframe after the animation completes.
backwards applies the first keyframe styles during the delay before the animation starts.
both combines the behavior of forwards and backwards.
Fill mode can be included in the animation shorthand, usually after delay and iteration count.
Cheat Sheet
⚡ Quick Reference
Question
Answer
Initial value
none
Applies to
Elements with CSS animations
Inherited
No
Animatable
No
Common use
Keeping final animation styles after an entrance effect
Defaults
Default Value
The initial value of animation-fill-mode is none. Outside the active animation period, the element does not retain keyframe styles from before or after the animation runs.
Reference
💎 Property Values
These keywords control style behavior before and after the animation plays.
Value
Example
Meaning
none
animation-fill-mode: none;
No keyframe styles apply before start or after end
forwards
animation-fill-mode: forwards;
Retains the final keyframe styles after the animation ends
backwards
animation-fill-mode: backwards;
Applies the first keyframe styles before the animation starts
both
animation-fill-mode: both;
Applies first keyframe styles before start and keeps final styles after end
initial
animation-fill-mode: initial;
Resets to the default value none
inherit
animation-fill-mode: inherit;
Inherits fill mode from the parent element
none
After the slide finishes, the box returns toward its original position instead of staying at the end.
Snaps back after end
Default behavior when fill mode is not set.
forwards
When the slide completes, the box stays at the final keyframe position on the right.
Keeps final styles
Click Restart above to replay and see the box stay at the end.
backwards
During the 1.2s delay, the box already uses the faded starting keyframe style before moving.
First keyframe during delay
Most visible when paired with animation-delay.
both
Uses the starting keyframe during the delay and keeps the final position after the animation ends.
Before delay + after end
Common choice for polished entrance animations.
Compare
When to Use Each Fill Mode
Value
Before animation
After animation
Best for
none
Normal styles
Normal styles
Looping decorative motion
forwards
Normal styles
Final keyframe styles
Entrance effects that should stay visible
backwards
First keyframe styles
Normal styles
Delayed starts that should look ready immediately
both
First keyframe styles
Final keyframe styles
Delayed entrances that also hold the end state
Preview
👀 Live Preview
This box slides right over 2 seconds and stays there with animation-fill-mode: forwards:
Reload the page to see the animation again. The box remains at its final position instead of jumping back to the start.
Hands-On
Examples Gallery
Try animation-fill-mode with forwards, backwards, both, and shorthand syntax.
📚 Fill Mode Basics
Learn how fill mode changes what happens before and after an animation runs.
Example 1 — Keep the Final Position with forwards
Move a box across the screen and keep it at the end position after the animation completes.
In animation: slideIn 0.6s ease-out forwards, the final keyword sets the fill mode so the toast stays on screen.
🧠 How animation-fill-mode Works
1
You define keyframes and timing
Set up start and end states, plus duration, delay, and iteration count.
Setup
2
You choose a fill mode
Decide whether first or last keyframe styles should apply outside the active animation window.
Fill mode
3
The browser applies styles before and after
backwards affects the delay period. forwards affects the time after completion.
Style retention
=
🎨
Polished animation results
Elements look intentional before, during, and after motion instead of snapping unexpectedly.
Compatibility
Universal Browser Support
animation-fill-mode is supported in all modern browsers alongside CSS animations.
✓ Baseline · CSS Animations
Keep animation styles reliably in modern browsers
Chrome, Firefox, Safari, Edge, and Opera all support every animation-fill-mode keyword.
98%Modern browser support
Google Chrome43+ · Desktop & Mobile
Full support
Mozilla Firefox16+ · Desktop & Mobile
Full support
Apple Safari9+ · macOS & iOS
Full support
Microsoft Edge12+ · Modern versions
Full support
Opera30+ · Modern versions
Full support
Legacy browsers
Very old browsers without CSS animation support also lack animation-fill-mode.
💻
Internet ExplorerIE 9 and earlier · No CSS animation support
None
animation-fill-mode property98% supported
Bottom line: Use animation-fill-mode confidently for entrance effects and delayed animations in modern projects.
Wrap Up
Conclusion
The animation-fill-mode property gives you control over styles before and after an animation runs. It is essential for polished entrance effects, delayed animations, and any motion that should not snap back when finished.
Reach for forwards when the final look should stay, backwards when the starting keyframe should appear during a delay, and both when you need both behaviors together.
Pair backwards with animation-delay to avoid pre-animation flashes
Use both for delayed cards, toasts, and modals
Test what happens after the animation ends in the UI
Respect prefers-reduced-motion for accessibility
❌ Don’t
Expect backwards to keep final styles after the animation
Use forwards on infinite looping animations unless intentional
Forget that default none may cause visible snapping
Confuse fill mode with animation direction or duration
Hide important content behind long delayed animations
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about animation-fill-mode
Use these points when styling before and after animations.
5
Core concepts
🎨01
Before & After
Styles outside active time.
Purpose
🔄02
none
Default reset behavior.
Default
▶️03
forwards
Keep final keyframe styles.
End state
⏪04
backwards
Start keyframe during delay.
Pre-start
⚡05
both
Combine both behaviors.
Complete
❓ Frequently Asked Questions
The animation-fill-mode property controls whether an element keeps animation styles before the animation starts, after it ends, or both.
The initial value is none, which means the element returns to its normal styles outside the active animation period.
forwards keeps the final keyframe styles after the animation ends. backwards applies the first keyframe styles before the animation starts, such as during a delay.
Use both when you want the starting keyframe styles during the delay and the ending keyframe styles to remain after the animation finishes.
Yes. Fill mode can be included in the animation shorthand, for example animation: fadeIn 1s ease-out forwards;