CSS animation-fill-mode Property

Description

The animation-fill-mode property defines what values are applied by the animation outside the time it is executing. By default, an animation will not affect property values between the time it is applied (the animation-name property is set on an element) and the time it begins execution (which is determined by the animation-delay property). Also, by default an animation does not affect property values after the animation ends (determined by the animation-duration property). The animation-fill-mode property can override this behavior.

Initial value
none
Applies to
All elements, :before and :after pseudo elements
Inherited
No
Media
Visual
Computed value
As specified
Animatable
No
CSS Version
CSS3
JavaScript syntax
object.style.animationFillMode

Syntax

animation-fill-mode: <single-animation-fill-mode> [ ',' <single-animation-fill-mode> ]* 

Values

<single-animation-fill-mode> = none | forwards | backwards | both
  • 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

<p>Move your mouse over the gray box!</p>
<div class="demo">
<div class="growsandstays">This grows and stays big.</div>
<div class="grows">This just grows.</div>
</div>
.demo {
  border-top: 100px solid #ccc;
  height: 300px;
}

@keyframes grow {
  0% { font-size: 0; }
  100% { font-size: 40px; }
}

.demo:hover .grows {
  animation-name: grow;
  animation-duration: 3s;
}

.demo:hover .growsandstays {
  animation-name: grow;
  animation-duration: 3s;
  animation-fill-mode: forwards;
}

Browser Support

Desktop
Explorer Edge Chrome Firefox Opera Safari
10124316309
Tablets / Mobile
Android Chrome Firefox Opera Safari Samsung
4343163094.0

Last updated by CSSPortal on: 17th October 2019