CSS animation-fill-mode Property
Description
The CSS animation-fill-mode property defines how an element should apply styles defined in an animation before it starts and after it ends. Without this property, an animated element will only display styles during the actual execution of the animation; once the animation finishes, the element immediately reverts to its original state as defined by its standard CSS rules. By using animation-fill-mode, developers gain fine-grained control over how the end or beginning states of an animation persist, allowing for smoother transitions and more predictable layouts when elements animate in or out of view. This is particularly useful when combined with keyframe animations that involve complex transformations or opacity changes.
One practical use of animation-fill-mode is in controlling the "holding" of styles from a keyframes animation after the animation completes. For example, an element that fades in using opacity changes can retain its final opacity value if the fill mode is set appropriately, instead of instantly reverting to being fully transparent. Similarly, an element that slides across the screen can remain in its final position rather than snapping back to its starting location, which ensures a more seamless user experience, especially in interactive interfaces where elements might need to stay visible or maintain certain visual states.
Additionally, animation-fill-mode can influence the initial state of an animation. If a developer wants an element to start in a specific style before the first keyframe executes, setting the fill mode allows the element to "adopt" the initial animation state immediately, rather than waiting for the animation to progress. This can help avoid visual glitches, such as flickering or sudden jumps, when an animation is triggered dynamically via JavaScript or on page load. Combined with other animation-related properties like animation-delay and animation-direction, animation-fill-mode becomes a powerful tool to precisely choreograph how elements appear, move, and interact in complex web animations.
Definition
- Initial value
- none
- Applies to
- All elements, :before and :after pseudo elements
- Inherited
- No
- Computed value
- As specified
- Animatable
- No
- JavaScript syntax
- object.style.animationFillMode
Interactive Demo
Syntax
animation-fill-mode: <single-animation-fill-mode> [ ',' <single-animation-fill-mode> ]*
Values
- noneThe animation will not apply any styles to the target before or after it is executing.
- forwardsThe target will retain the computed values set by the last keyframe encountered during execution.
- backwardsThe animation will apply the values defined in the first relevant keyframe as soon as it is applied to the target, and retain this during the animation-delay period.
- bothThe animation will follow the rules for both forwards and backwards, thus extending the animation properties in both directions.
Example
Browser Support
The following information will show you the current browser support for the CSS animation-fill-mode property. Hover over a browser icon to see the version that first introduced support for this CSS property.
This property is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 1st January 2026
