CSS animation-direction Property

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 4 Examples
Animations & Timing

What You’ll Learn

The animation-direction property controls which way a CSS animation plays. Use it to move elements forward, backward, or smoothly back and forth without a visible jump at the end of each cycle.

01

Playback Flow

Control animation direction.

02

Syntax

Four keyword values.

03

normal

Default forward playback.

04

reverse

Play from end to start.

05

alternate

Smooth back-and-forth motion.

06

Shorthand

Works with animation too.

Definition and Usage

The animation-direction CSS property sets whether an animation runs from the first keyframe to the last, from last to first, or alternates between those directions on repeated cycles.

This is especially useful for bouncing loaders, sliding panels that return smoothly, pulsing indicators, and any motion that should feel continuous rather than snapping back to the start.

💡
Beginner Tip

For a smooth ping-pong effect, pair animation-direction: alternate with animation-iteration-count: infinite. The box moves forward, then backward, without jumping.

📝 Syntax

Set animation-direction with one of its keyword values:

syntax.css
selector {
  animation-direction: normal | reverse | alternate | alternate-reverse;
}

Basic Example

animation-direction.css
.box {
  animation: move 4s ease-in-out infinite;
  animation-direction: reverse;
}

Syntax Rules

  • The initial value is normal, which plays keyframes from start to end.
  • alternate and alternate-reverse only show their full effect when the animation repeats.
  • When multiple animations run on one element, use comma-separated direction values matching each animation.
  • Direction can be included in the animation shorthand after timing and iteration values.
  • Combine with animation-iteration-count: infinite for continuous back-and-forth motion.

⚡ Quick Reference

QuestionAnswer
Initial valuenormal
Applies toElements with CSS animations
InheritedNo
AnimatableNo
Common useBouncing, sliding, and looping motion effects

Default Value

The initial value of animation-direction is normal. The animation plays from the first keyframe to the last, and on each repeat it starts again from the beginning.

💎 Property Values

These keyword values define how animation cycles are played over time.

ValueExampleMeaning
normalanimation-direction: normal;Plays forward from start to end on every iteration
reverseanimation-direction: reverse;Plays backward from end to start on every iteration
alternateanimation-direction: alternate;Alternates forward and backward on each iteration
alternate-reverseanimation-direction: alternate-reverse;Starts backward, then alternates forward and backward
initialanimation-direction: initial;Resets to the default value normal
inheritanimation-direction: inherit;Inherits direction from the parent element
normal

The box always moves left to right, then jumps back to the start on each repeat.

Forward each cycle

Default playback direction.

reverse

The box always moves right to left, starting from the end position of the keyframes.

Backward each cycle

Every iteration runs in reverse.

alternate

The box moves forward, then smoothly returns backward without jumping to the start.

Ping-pong motion

Most popular choice for bouncing effects.

alternate-reverse

The first cycle runs backward, then the animation alternates direction on later repeats.

Reverse first, then alternate

Useful when the element should begin at the end state.

reverse vs alternate

ValueCycle 1Cycle 2Best for
reverseEnd → startEnd → start againAlways running backward
alternateStart → endEnd → startSmooth back-and-forth looping

👀 Live Preview

This box uses animation-direction: alternate to slide back and forth smoothly:

The box moves right, then returns left, repeating without a visible jump.

Examples Gallery

Try animation-direction with reverse, alternate, normal, and shorthand syntax.

📚 Direction Keywords

See how each keyword changes the way the same keyframe animation is played.

Example 1 — Play the Animation in Reverse

Move a box from right to left by setting animation-direction: reverse.

animation-direction-reverse.html
<style>
  @keyframes move {
    from { transform: translateX(0); }
    to { transform: translateX(200px); }
  }
  .box {
    width: 100px;
    height: 100px;
    background: blue;
    animation: move 4s ease-in-out infinite;
    animation-direction: reverse;
  }
</style>

<div class="box"></div>
Try It Yourself

How It Works

The keyframes still define 0 to 200px, but reverse plays them from end to start on every cycle.

Example 2 — Smooth Back-and-Forth with alternate

Create a bouncing slider that returns smoothly instead of jumping back to the start.

animation-direction-alternate.css
.slider {
  animation: move 2s ease-in-out infinite;
  animation-direction: alternate;
}
Try It Yourself

How It Works

On odd iterations the box moves forward; on even iterations it moves backward, creating continuous ping-pong motion.

Example 3 — Default Forward Playback

Use normal when the animation should restart from the beginning on each repeat.

animation-direction-normal.css
.loader-bar {
  animation: fill 1.5s linear infinite;
  animation-direction: normal;
}
Try It Yourself

How It Works

Each loop restarts from 0% width because normal always plays the keyframes forward from start to end.

⚡ Shorthand Usage

Set direction directly inside the animation shorthand for shorter, readable code.

Example 4 — Direction in the Animation Shorthand

Include alternate-reverse as part of the shorthand declaration.

animation-shorthand-direction.css
.pulse-dot {
  animation: pulse 1.2s ease-in-out infinite alternate-reverse;
}
Try It Yourself

How It Works

The shorthand order includes name, duration, timing function, iteration count, and direction. Here, the dot begins with the larger scale and alternates back.

🧠 How animation-direction Works

1

You define keyframes

Create a path from a start state to an end state with @keyframes.

Keyframes
2

You choose a direction

Set normal, reverse, alternate, or alternate-reverse.

Direction
3

The browser plays each cycle

On repeat, the browser follows your direction rules instead of always restarting forward.

Playback
=

Dynamic motion

The same keyframes can feel completely different depending on the direction you choose.

Universal Browser Support

animation-direction is supported in all modern browsers alongside CSS animations.

Baseline · CSS Animations

Control animation flow in modern browsers

Chrome, Firefox, Safari, Edge, and Opera all support every animation-direction keyword.

98% Modern browser support
Google Chrome43+ · Desktop & Mobile
Full support
Mozilla Firefox16+ · Desktop & Mobile
Full support
Apple Safari9+ · macOS & iOS
Full support
Microsoft Edge12+ · Modern versions
Full support
Opera30+ · Modern versions
Full support

Legacy browsers

Very old browsers without CSS animation support also lack animation-direction.

💻
Internet Explorer IE 9 and earlier · No CSS animation support
None
animation-direction property 98% supported

Bottom line: Use animation-direction freely in modern projects. Test looping animations on mobile for smooth performance.

Conclusion

The animation-direction property lets you control how CSS animations play across repeated cycles. It turns simple keyframes into forward motion, backward motion, or smooth alternating movement.

Start with normal, then try alternate for bouncing effects and reverse when you want every cycle to run backward.

💡 Best Practices

✅ Do

  • Use alternate with infinite for smooth looping motion
  • Pair direction with an appropriate easing function like ease-in-out
  • Test repeated animations for visible jumps or stutter
  • Respect prefers-reduced-motion for accessibility
  • Keep direction logic in CSS rather than duplicating reversed keyframes

❌ Don’t

  • Expect alternate to matter on a single-run animation
  • Confuse reverse with alternate
  • Use infinite looping motion for essential content visibility
  • Forget that shorthand order matters when including direction
  • Overuse distracting back-and-forth animations across an entire page

Key Takeaways

Knowledge Unlocked

Five things to remember about animation-direction

Use these points when shaping animation playback.

5
Core concepts
▶️02

normal

Default forward direction.

Default
🔄03

alternate

Smooth back-and-forth loops.

Popular
04

reverse

Every cycle runs backward.

Reverse
05

Needs Repeats

Alternate shines with loops.

Pattern

❓ Frequently Asked Questions

The animation-direction property controls whether a CSS animation plays forward, backward, or alternates between both directions on each cycle.
The initial value is normal, which plays the animation from start to end on every iteration.
reverse plays every iteration backward. alternate plays forward on odd cycles and backward on even cycles, creating a smooth back-and-forth motion.
Use alternate for bouncing, pulsing, or sliding effects that should return smoothly without jumping back to the start.
Yes. Direction can be included in the animation shorthand, for example animation: move 2s ease-in-out infinite alternate;

Practice in the Live Editor

Open the HTML editor, try animation-direction: alternate, and watch the back-and-forth motion.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful