CSS propertyAnimations

animation-fill-mode

Decides how the element looks before the animation starts and after it ends.

Initial value
none
Inherited
No
Animatable
no
Applies to
all elements and the ::before and ::after pseudo-elements
JavaScript
element.style.animationFillMode = "forwards"
On this page

Example

#
CSS
.card {
  animation: fade-up 0.6s ease-out 0.3s both;
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(12px); }
}
Preview

Definition and usage

#

By default an animation affects the element only while it runs. Before the start (during the delay) and after the end, the element returns to its normal styles. The animation-fill-mode property lets you change that.

forwards keeps the element in the state of the last keyframe, backwards applies the first keyframe already during the delay, and both combines the two behaviors.

For entrance effects with a delay, both is usually the best choice: the element does not flash before the start and does not return to the initial state after the end.

Syntax

#
Syntax
animation-fill-mode: none | forwards | backwards | both;

Values

#
  • none

    Before the start and after the end, the element stays in its normal place.
  • forwards

    After the end, the element stays in the state of the last keyframe.
  • backwards

    During the delay, the element already sits in the state of the first keyframe.
  • both

    The first keyframe before the start and the last one after the end.

Values in practice

#

none

Before the start and after the end, the element stays in its normal place.
.demo { animation-fill-mode: none; }

forwards

After the end, the element stays in the state of the last keyframe.
.demo { animation-fill-mode: forwards; }

backwards

During the delay, the element already sits in the state of the first keyframe.
.demo { animation-fill-mode: backwards; }

both

The first keyframe before the start and the last one after the end.
.demo { animation-fill-mode: both; }

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • Set delayed entrance effects with both, otherwise the element will flash in its final state before the start.
  • Instead of a permanent forwards, consider putting the target styles in a regular rule. They are easier to override later.

Related entries

#

Spotted a mistake or missing an example? Write to us.