Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Transforms, Transitions and Animations

The animation-direction property

Reference for the CSS animation-direction property: normal, reverse, alternate and alternate-reverse, how easing flips on reverse plays, with live examples.

The animation-direction property decides in which direction each iteration of a CSS animation plays. By default every iteration runs from the first keyframe to the last and then jumps back to the start. With reverse it runs backwards, and with the two alternate values it flips direction on every iteration so the motion goes back and forth smoothly.

It only matters when an animation repeats or when you want to play the keyframes backwards. For a single forward run, the default normal is what you want.

CSS
.pulse {
  animation: slide 1s ease-in-out infinite;
  animation-direction: alternate;
}

Try it

Four directions

The blue dot is the from keyframe and the red dot is the to keyframe. Watch where each row starts and how the first two rows jump back while the last two glide.

Syntax

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

/* several animations, one value each */
animation-direction: normal, alternate;
  • Initial value: normal
  • Applies to: all elements, ::before and ::after
  • Inherited: no
  • Animatable: no
  • Computed value: as specified

Values

Value Description
normal Every iteration plays forwards, from 0% to 100%.
reverse Every iteration plays backwards, from 100% to 0%.
alternate Odd iterations (1st, 3rd, ...) play forwards, even iterations (2nd, 4th, ...) play backwards.
alternate-reverse Odd iterations play backwards, even iterations play forwards.

Usage notes

  • Counting starts at 1. In alternate, the first iteration is forwards. In alternate-reverse, the first iteration is backwards. A one-time animation (animation-iteration-count: 1) with alternate therefore looks the same as normal.
  • Easing is flipped too. When an iteration plays backwards, the timing function is reversed as well, so ease-in becomes an ease-out on the way back. This is why alternate looks natural with easing such as ease-in-out.
  • Pairs well with infinite. Breathing, pulsing and ping-pong effects are the classic use. Use animation-iteration-count: 2 (or any even number) with alternate to end where you started.
  • Interacts with fill modes. animation-fill-mode: backwards shows the first keyframe in the direction of the first iteration, which is the 100% keyframe with reverse. See animation-fill-mode.
  • Lists are matched by position. With several animation names, the nth direction belongs to the nth name. A shorter list repeats.
  • Reduced motion. Looping animations can bother some people. Wrap them in a prefers-reduced-motion: no-preference media query or switch them off for users who ask for less motion.

Browser support

Supported in every current browser, including alternate-reverse.