Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

animation-direction: choose the direction of each iteration

Reverse keyframe progression or alternate it without confusing direction with playback speed.

Version: CSS Modules

Syntax

animation-direction: normal | reverse | alternate | alternate-reverse;

animation-direction has four keywords. Initial normal plays each iteration forward; reverse plays each backward. alternate starts forward and reverses every second iteration, while alternate-reverse starts backward and then alternates. Iterations are counted from one for this odd/even distinction. A comma-separated list assigns directions to corresponding animation names; the property is not inherited.

Direction changes progression through keyframes and also reverses the apparent easing. An ease-in curve played backward looks like ease-out; merely subtracting a forward sampled value from one does not generally produce the reversed sample at the same elapsed time. Direction does not change duration, add iterations or mean a negative playback rate. Fill behavior and a negative delay can determine which part of which directed iteration is visible.

The example animates horizontal translation from 0px to 100px across three one-second iterations. At 250,1250,2250ms, linear forward playback gives 25,25,25; reverse gives 75,75,75; alternate gives 25,75,25; alternate-reverse gives 75,25,75. With ease-in at 250ms, measured forward and reverse positions are 9.346 and 62.186, rounded to three decimals. The second result is not 100 minus the first.

Examples

const style=document.createElement('style');style.textContent='@keyframes move{from{transform:translateX(0px)}to{transform:translateX(100px)}}';document.head.append(style);
const sample=(direction,easing,times)=>{const box=document.createElement('div');box.style.cssText='animation:move 1s 3 both paused';box.style.animationDirection=direction;box.style.animationTimingFunction=easing;document.body.append(box);const animation=box.getAnimations()[0];return times.map(time=>{animation.currentTime=time;return new DOMMatrix(getComputedStyle(box).transform).m41.toFixed(3)}).join(',')};
for(const direction of ['normal','reverse','alternate','alternate-reverse'])console.log(direction+'='+sample(direction,'linear',[250,1250,2250]));
console.log('ease-in='+sample('normal','ease-in',[250])+'; reversed-ease-in='+sample('reverse','ease-in',[250]));

Result

normal=25.000,25.000,25.000
reverse=75.000,75.000,75.000
alternate=25.000,75.000,25.000
alternate-reverse=75.000,25.000,75.000
ease-in=9.346; reversed-ease-in=62.186

The CSSAnimations are paused and sampled at explicit local times, away from iteration boundaries. This measures direction and easing, not frame scheduling. Provide reduced-motion alternatives for nonessential movement.

Sources