Tip 51 Leverage CSS for Animations

In this tip, you’ll learn how to use CSS for animations.

The last tip isn’t even a JavaScript tip. Instead, it’s a tip about when to stop using JavaScript.

The key to writing readable code is to use the best tool for the job. JavaScript used to be the best tool for animations. In fact, there were entire libraries dedicated to using JavaScript to create drop-down menus or to animate slide-in elements.

It’s much easier now. CSS is replacing JavaScript for simple animations. That’s great. Now you don’t have to worry about using the right timeouts or calculating odd-size constraints. CSS will take care of all that for you. You’ll still need JavaScript for more complicated animations, but for most common tasks, ...

Get Simplifying JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.