InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

CSS animation

  • animation overview
  • animation-name
  • animation-duration
  • animation-timing-function
  • animation-delay
  • animation-iteration-count
  • animation-direction
  • animation-fill-mode
  • animation-play-state
  • animation shorthand
 
  • Home
  • > Tutorials
  • > CSS
  • > CSS properties
  • > CSS Animation

CSS animation-fill-mode

on Mar 24, 2016

CSS animation-fill-mode property defines what values are applied by the animation outside its execution time window. These two periods are considered outside animation:

  • During delay when animation has not started
  • After animation has finished

In case animation-name has multiple values, animation-fill-mode can also have multiple values.

CSS property animation-fill-mode

CSS version: CSS 3
Value: [none | forwards | backwards | both] [, ...]*
Initial: none
Applies to: all elements, ::before and ::after pseudo-elements
Inherited: no

animation-fill-mode values

valueWhen is it applicableDescription
none-The animation has no effect outside its execution time window
forwardsProperty after end of animation
  • If (iteration-count > 0): After the animation ends, the end iteration keyframe property values will apply
  • If (iteration-count == 0): start of first iteration keyframe values will apply.
backwardsProperty during delay periodDuring the period defined by animation-delay, the property values defined in the first iteration keyframe will apply
bothProperty during and after end of animationThe effects of both forwards and backwards fill apply
Also note that animation direction will impact first and last iteration values.

Example – animation-fill-mode

In the following code, CSS property animation-fill-mode can be changed to the following values
  • none
  • forwards
  • backwards
  • both
<style>
@keyframes left-to-right {
  0% {left:0;top:0;}
  100% {left:200px;top:0;}
}
.box {
  z-index:1; position:fixed; left: 100px; top:100px;
  background-color:lightgreen;
  animation-name:left-to-right;
  animation-duration:4s; animation-delay:2s;
  animation-fill-mode:none;
}
.obj-init-pos {position:fixed; left:100px; top:100px; color:#ccc;}
.ani-start-pos {position:fixed; left:0; top:0; color:#ccc;}
.ani-end-pos {position:fixed; left:200px; top:0; color:#ccc;}
</style>

<div class="box">Object</div>
<div class="obj-init-pos">Object initial position</div>
<div class="ani-start-pos">Animation start position</div>
<div class="ani-end-pos">Animation end position</div>
animation-fill-mode refresh done
try it online

Few points to note in above example:

animation-fill-mode value Behaviour
none Object stays at original position during delay and comes back at original position after animation
forwards Object stays at original position during delay and remains at animation end position after animation
backwards Object take animation start position even during delay and comes back at original position after animation
both Object take animation start position even during delay and remains at animation end position after animation

Specification

  • W3C CSS 3 animation-fill-mode specification

Suggested posts:

  1. CSS – align div in center vertically
  2. CSS animation-timing-function
  3. CSS animation-delay
  4. CSS animation-iteration-count
  5. CSS animation-name
  6. CSS animation-direction
  7. CSS animation-duration
  8. CSS text-transform – capitalize, uppercase and lowercase text
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged CSS, CSS Animation, CSS properties, Tutorials
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress