Choosing the Right Animation Technique

Let's cover some simple steps to choosing the right animation technique.

Now, decision time. How should you choose between setInterval(), requestAnimationFrame(), or CSS to animate your page? The answer depends on how complex your animation is. In theory, CSS animations are more efficient performance-wise, but you can’t do everything with them.

Here’s how you might want to approach your decision:

  • Use setInterval() if the animation isn’t in real-time and should just happen at regular intervals.

  • Favor CSS if the animation happens in real-time and can be managed with it.

  • Use requestAnimationFrame() for any other case.

Get hands-on with 1200+ tech skills courses.