The animation-fill-modeCSS property sets how a CSS animation applies styles to its target before and after its execution.

The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

It is often convenient to use the shorthand property animation to set all animation properties at once.

The 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. The first relevant keyframe depends on the value of animation-direction:

animation-direction

first relevant keyframe

normal or alternate

0% or from

reverse or alternate-reverse

100% or to

both

The animation will follow the rules for both forwards and backwards, thus extending the animation properties in both directions.

Note: When you specify multiple comma-separated values on an animation-* property, they will be assigned to the animations specified in the animation-name property in different ways depending on how many there are. For more information, see Setting multiple animation property values.

Formal syntax

Example

You can see the effect of animation-fill-mode in the following example. It demonstrates how, for an animation that runs for an infinite time, you can cause it to remain in its final state rather than reverting to the original state (which is the default).