CSS animation-fill-mode Property
The animation-fill-mode property in CSS defines how an animated element should behave before and after the animation runs.
1. Syntax
2. Accepted Values
| Value | Description |
|---|---|
none (default) | The element does not retain any animation styles before or after it runs. |
forwards | The element keeps the last frame of the animation after it completes. |
backwards | The element applies the first frame of the animation before it starts. |
both | Combines forwards and backwards, keeping both the first and last frames. |
3. Example – Using forwards (Keeps Last Frame)
✅ The box stays at the last position after the animation ends.
4. Example – Using backwards (Applies First Frame Early)
✅ The box starts invisible during the 2-second delay.
5. Example – Using both (Keeps First & Last Frames)
✅ The box starts small (before animation) and stays large (after animation).
6. Best Practices
✔ Use forwards to maintain the final animation effects.
✔ Use backwards when using animation-delay for smoother transitions.
✔ Use both when you need a smooth entry and exit effect.

