Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Transforms, Transitions and Animations

The animation-fill-mode property

Reference for the CSS animation-fill-mode property: none, forwards, backwards and both, with a live example showing styles before and after an animation.

The animation-fill-mode property controls what an element looks like outside the active part of its animation: during the animation-delay before it starts, and after it finishes. By default an animation has no effect in those periods, so the element snaps back to its normal styles the moment the animation ends.

Use forwards to keep the final keyframe, backwards to apply the first keyframe during the delay, or both to do both.

CSS
.toast {
  animation: slide-in 400ms ease-out 1s;
  animation-fill-mode: both;
}

Try it

Before and after

During the delay, the backwards and both boxes already sit at the first keyframe (orange, shifted right). After the end, only forwards and both stay at the last keyframe (green); the others jump back to grey at the left.

Syntax

CSS
animation-fill-mode: none | forwards | backwards | both;

/* one value per animation name */
animation-fill-mode: none, both;
  • Initial value: none
  • Applies to: all elements, ::before and ::after
  • Inherited: no
  • Animatable: no
  • Computed value: as specified

Values

Value Description
none The animation affects the element only while it is running.
forwards After the animation ends, the element keeps the values from the last keyframe that was reached.
backwards During the delay, the element takes the values of the first keyframe (as determined by animation-direction).
both Applies both forwards and backwards.

Usage notes

  • "Last keyframe" depends on direction and count. With forwards, the retained state is the end of the final iteration. With reverse or an even number of alternate iterations, that is the 0% keyframe, not 100%.
  • The usual choice is both for entrance animations with a delay: the element is already in its starting pose while it waits and stays in its final pose afterwards.
  • Fill is not a real style change. The retained values come from the animation, not from your normal rules, and they sit at the animation level of the cascade. Editing the element's regular styles will not override them unless you remove the animation.
  • Staggered lists need backwards. If items have increasing delays and start invisible in the keyframes, without backwards they would flash visible until their turn.
  • Zero-length effects. If an animation has a duration of 0s, forwards still applies the end state, which is a handy way to set styles through the animation layer.
  • Many stuck animations. Filled animations stay alive and keep being tracked by the browser. For something you only need to be static, put the final values in normal CSS instead.

Browser support

Supported in every current browser.