English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS Reference Manual

CSS @rules (RULES)

Complete List of CSS Properties

CSS3 animation-fill-Usage and examples of mode attribute

CSS3 animation-fill-The mode attribute specifies how the style is applied to the target before and after the CSS animation is executed.

The following table summarizes the usage context and version history of this attribute.

Default value:none
Applies to:All elements ::before and ::after Pseudo-element
Inheritance:None
Animated by:No.See also: Animation properties.
Version: CSS3New feature of
JavaScript syntax:    object.style.animationFillMode="forwards"

animation-fill-Syntax of mode usage

The syntax of this attribute is as follows:

animation-fill-mode: none | forwards | backwards | both | initial | inherit

The following example demonstrates how to use the animation-fill-mode attribute.

.box {
    width: 50px;
    height: 50px;
    background: red;
    position: relative;
    /* Chrome, Safari, Opera */
    -webkit-animation-name: moveit;
    -webkit-animation-duration: 4s;
    -webkit-animation-fill-mode: forwards;
    
    animation-name: moveit;
    animation-duration: 4s;
    animation-fill-mode: forwards;
}
 
/* Chrome, Safari, Opera */
@-webkit-keyframes moveit {
    from {left: 0;}
    to {left: 50%;}
}
 
@keyframes moveit {
    from {left: 0;}
    to {left: 50%;}
}
Test and see‹/›

Attribute values

The following table describes the values of this attribute.

ValueDescription
noneThe animation will not apply any styles to the target before or after it is executed.
forwardsAfter the animation ends (determined byanimation-iteration-count). The animation will apply the attribute values at the end of the animation.
backwardsThe animation will apply the attribute values defined in the keyframes, which will be determined byanimation-delayThe first iteration of the animation starts within the time period defined by the attribute. These are the values of the from keyframe (animation-directionFor normal or alternate) or to the value of the keyframe (animation-directionFor reverse or alternate-reverse).
bothThe animation will follow the rules of forward and backward, thus expanding the animation properties in both directions.
initialSet this attribute to its default value.
inheritIf specified, the associated elements adopt the parent element's animation-fill-The calculated value of mode attribute.

Browser compatibility

animation-fill-The compatibility of mode attribute across browsers, all major browsers support this attribute.

  • Firefox 5+ -moz-,15 +

  • Google Chrome 4+ -webkit-

  • Internet Explorer 10+

  • Apple Safari 4+ -webkit-

  • Opera 12+ -o-,15+ -webkit-

Further reading

Please refer to the following tutorials:CSS3Animation.

Relative attributes and rules:   animation,animation-name,animation-duration,animation-timing-function,animation-delay,animation-iteration-count,animation-direction,animation-play-state,@keyframes.