There’s lots of great stuff you can do with website animations if you have an eye for design. But how do you create these animations from scratch?
In this post, I’ll showcase a handful of libraries and tools for building custom animation effects predominantly with HTML5 and CSS3 code. Some of these technologies are still in their infancy, but over time I expect HTML5 animation to dominate major portions of the web.
The Basics of Web Animation
But since the invention of HTML5 and CSS3, it’s possible to create transitions and animations with CSS properties. There are now hundreds of free pure CSS animations that can be copied & modified for modern web projects—no JS required.
So where should a new developer get started? And how should HTML5/CSS3 animations be applied to modern web development?
Let’s delve into the different aspects of custom animations and check out some free code snippets along the way.
Transition vs. Animation Properties
There are two primary modes of creating CSS animation: with the transition property and the animation property. Both have widespread browser support but they behave in different ways.
Transitions require much less code but are also a lot simpler. Animations provide incredible amounts of customization and functionality, but you have to raw code animation keyframes from scratch.
Transitions define something in two states: a beginning state and an ending state. There’s little control between these two states other than the time of the transition and the easing quality.
Animations are much more powerful and technical than transitions. They allow for custom delays, multiple states, and progressive changes over time. Transitions move from A to B, then sometimes back to A. But animations can move from A to Z or any other combination of letters in between.
Kirupa has a really great video and a supplementary article explaining the basics between these two properties.
Transitions generally work best with page elements that have single instances of animations. Think about link hovers, button clicks, or dropdown menus. These only have a single type of movement on the page, and once these elements animate they usually go back to their original state(after the click or moving off hover).
So which should you use? It always depends on context, but keep in mind that animations are much more complex so they should only be used when needed for complex situations that can’t be handled with a transition(A to B).
Note that it is possible to use animation effects for simple triggers like clicks or hovers. But the only reason to do so would be if you need heavily customized animation effects like a button jiggling around the page.
- CSS vs. JS Animation: Which is Faster?
- CSS3 animation vs CSS3 transition
HTML5 Canvas Animation
You can build lots of cool stuff like canvas loaders and other similar resources. But most HTML5 canvas animations are purely aesthetic and don’t relate to interactive elements.
This is because canvas elements themselves embed into the page. So unless the entire page is built in a canvas(NOT recommended) then you’ll be limited to whatever elements are in your canvas.
Since HTML5 games are built with the canvas API it makes sense in these scenarios.
You can do some really cool stuff like custom sprite animation and background motion for repeating tiles. I’ve never spent much time building HTML5 games, but there are many great tutorials online covering this exact subject.
There’s also free tools like Animatron to help designers & developers create custom HTML5 animations.
Animatron offers a free account but limits the total number of projects for each account. As your skills improve you might prefer to create animations from scratch. But a code-generating motions editor is always valuable if you need to save time.
To learn more about canvas animations check out these related articles. And just remember if you want to master HTML5 animation then practice is the key to success.
- Creating a Simple HTML5 Canvas Animation
- Resizing and Cropping Images with Canvas
- Animated Map Path for Interactive Storytelling
- 9 Mind-Blowing Canvas Demos
Free Animation Libraries
The popularity of frontend animation has led to a wide variety of animation libraries There are so many options available that it may be tough deciding where to start.
I’ve curated the most popular choices below that you can choose from. Simply download a copy and try it out in a sample project. Advancements in animation have come a long way and you may be surprised at how much is possible with a free code library.
Undeniably the most popular CSS animation library is Animate.css created by Daniel Eden. It’s still actively updated with quality code and a lively set of pre-built animations.
The landing page lets you test different animation styles to see how they work on-page elements. With a basic CSS class you can represent very detailed animations from zooms, pans, fades, and even a mixture of these effects.
If you can get by with CSS as your animation language then I highly recommend Animate.css. Grab a free copy from GitHub and test it for yourself.
A similar animation library is CSShake, albeit with limited motion choices. The library pertains directly to CSS animations that shake and force certain elements to vibrate on the page.
It’s easy to keep these animations going all the time. But they can be rather annoying after a lengthy period. I recommend using this scarcely or only as a reminder for an on-page message box or signup form.
Hover.css is a very simple open-source CSS animation library made for hover actions. Whenever the user hovers over a button it can be targeted for a certain type of motion effect. This is applied directly with Hover.css and includes rotations, skews, and even background transitions.
Most of the Hover.css effects apply directly to page buttons rather than links. Although this can be used on any hoverable element, it’s best used for page elements that require some attention.
Zurb recently published the Foundation 6 release which included a custom animation library called Motion UI. The landing page is more like a playground to see what can be done and how the effects work.
It’s a really nice intermediate library where the effects can be pragmatic, aesthetic, or both. You can fade elements into view or have them wiggle on hover. There’s a handful of animation types to choose from and it makes animating an interface easier than ever.
To learn more about this newer library check out the Motion UI documentation and download a copy from the Zurb GitHub repo.
It’s mostly a library for animating elements into and out of view. But it has its place in a great landing page with custom animations and sequence-animated elements.
It supports retina displays and has a modular design where you can append custom animations into the Mo.js library. It really is the most advanced JS library for animation I’ve ever found.
Granted not everyone is looking for this much detail in their animations. But if you are then check out Mo.js on GitHub and try it out.
Here’s another cool all-around library called Ani.js which works as a custom animation/component library. Animations can be tied to page widgets like tabs, accordion menus, and scroll-to-reveal windows.
This is very detailed and although it’s easy to setup, it takes a lot of practice to fully understand. If you’re looking for a great animation library that goes beyond jQuery then AniJS might be right for you.
Best Free Code Snippets
If you’re looking for freebies like code snippets then I’ve got ya covered. After scouring CodePen I was able to organize this small gallery of free open source pens from web developers.
Embedding all 20+ examples would make this page load very slow, so instead, I just have a placeholder screenshot that links to the pen. If you see anything you like just click over to the pen and check it out! All code is open source so you can copy and edit as you see fit.