CSS propertyAnimations

animation-direction

Sets the playback direction of the animation: forwards, backwards, or alternating.

Initial value
normal
Inherited
No
Animatable
no
Applies to
all elements and the ::before and ::after pseudo-elements
JavaScript
element.style.animationDirection = "alternate"
On this page

Example

#
CSS
.float {
  animation: float 3s ease-in-out infinite alternate;
}

@keyframes float {
  to { translate: 0 -8px; }
}
Preview

Definition and usage

#

The animation-direction property decides whether the animation runs from from to to (normal), from the end to the start (reverse), or alternates between both directions (alternate).

With a looping animation using normal, the element jumps back to the first keyframe after the last one, which can show up as a jolt. alternate makes it return smoothly along the same path.

alternate-reverse works like alternate, but starts with a backward run.

Syntax

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

Values

#

Values in practice

#

normal

From left to right, then a jump back to the start.
.demo { animation-direction: normal; }

reverse

From right to left, then a jump.
.demo { animation-direction: reverse; }

alternate

Smoothly back and forth.
.demo { animation-direction: alternate; }

alternate-reverse

Back and forth, starting from the end.
.demo { animation-direction: alternate-reverse; }

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • alternate almost always fits calm, looping movements (floating, breathing).
  • In the animation shorthand you can add the direction after the iteration count: … infinite alternate.

Related entries

#

Practise it in lessons

#

Spotted a mistake or missing an example? Write to us.