CKTIS / CSS
animation-fill-mode: values outside the active interval
Choose whether animation values apply during its delay, after it finishes, or in both periods.
Version: CSS Modules
Syntax
animation-fill-mode: both;animation-fill-mode controls the effect outside the active interval; it does not change the interpolation while the animation is running. The initial none leaves underlying styles in control before and after. backwards applies the starting keyframe during a positive animation-delay, forwards retains the value at the end of the last played portion, and both combines them. In a comma-separated list, each value matches an animation-name; shorter lists repeat.
Starting and ending do not always mean the written 0% and 100% keyframes. animation-direction changes the starting side, and animation-iteration-count can end on a reversed cycle or partway through a fractional cycle. A zero iteration count with forwards uses the value that would start the first iteration. Filling does not write a permanent declaration into the element: removing the animation also removes its fill effect, so use an ordinary final-state style when that state must remain independently.
The example uses underlying opacity 0.3, keyframes from 0.2 to 0.8, a 1s delay and a 1s linear cycle. At 0ms, none/forwards show 0.3 and backwards/both show 0.2. At 1500ms all four show 0.5. At 2500ms none/backwards return to 0.3 while forwards/both show 0.8. Reversing a both-filled animation changes its before/after values to 0.8 and 0.2. Setting animation-name to none restores 0.3.
Examples
const style=document.createElement('style');
style.textContent='@keyframes fill-demo{from{opacity:0.2}to{opacity:0.8}}';document.head.append(style);
const make=(fill,direction='normal')=>{const el=document.createElement('div');el.style.cssText='opacity:0.3;animation-name:fill-demo;animation-duration:1s;animation-delay:1s;animation-timing-function:linear;animation-play-state:paused';el.style.animationFillMode=fill;el.style.animationDirection=direction;document.body.append(el);return {el,animation:el.getAnimations()[0]}};
const modes=['none','forwards','backwards','both'],rows=modes.map(mode=>make(mode));
const read=(row,time)=>{row.animation.currentTime=time;return Number(getComputedStyle(row.el).opacity).toFixed(1)};
for(const time of [0,1500,2500])console.log(time+'ms='+rows.map(row=>read(row,time)).join(','));
const reverse=make('both','reverse');console.log('reverse='+[0,2500].map(time=>read(reverse,time)).join(','));
rows[3].el.style.animationName='none';console.log('removed='+getComputedStyle(rows[3].el).opacity);Result
0ms=0.3,0.3,0.2,0.2 1500ms=0.5,0.5,0.5,0.5 2500ms=0.3,0.8,0.3,0.8 reverse=0.8,0.2 removed=0.3
Executed in Chromium 157.0.8103.51. The test seeks paused CSS animations to precise before/active/after times and reads actual opacity. It does not measure wall-clock scheduling or assert that filling changes the element’s underlying style.