Entrance effects using CSS animation can add some flair to your email. Unlike more ambitious kinetic email designs that may involve a lot of development time including the production of both kinetic and fallback versions of an email, entrance animation effects leveraging CSS 2D transforms can deliver some pizzaz without a lot of extra effort.
For this post, we’ll cover two kinds of entrance effects, fly-in and pop-in.
Everyone has seen entrance effects used in slides and presentations where content slides in or fades into the presentation. Although CSS animation support is limited to more modern email clients, these entrance effects are relatively simple to implement and may provide a cool effect to your email depending on your audience.
The key to these examples below is that you can just code your emails the way you’re used to and only need to wrap the elements you want the effect with a div to have them come alive in email clients that support CSS animation.
Fly from left
(Animation above repeats for illustration purposes)
Although you can use other methods such as margin and absolute positioning to perform the fly-in animation, translate allows an element to be moved relative to its original position without affecting the elements around it.
With 2D Transforms the element can grow, move or shrink and the elements around it behave as if the element has not moved. This is great since you don’t have to design your emails any differently to accommodate entrance effects.
Then we wrap any element we want to “fly-in” with a div with the class “fly-in-left”. Now email clients that don’t support CSS animations will just display the content statically and clients that support CSS animations will display the content flying in from the left.
<div class="fly-in-left">Fly from left</div>
Adding a delay
What if we want to add a delay before having the element “fly-in”? The obvious technique would be to add an animation-delay property. However that would mean the content would be displayed for a brief moment before the fly-ing in – not what we want.
We could address the issue above by styling it so the element is hidden before executing the animation, but the animation would revert to being hidden after it completes!
We could address the next issue with animation-fill-mode: forwards;. Which would leave the element visible at the end of the animation… BUT… this isn’t supported by some old Android clients (specifically 2.x – if you don’t need that support you can use this method).
Our solution to the delay is to let the animation “do nothing” for a percentage of the time. The following 3 second animation starts the 1 second long fly-in at the 2 second (66%) mark.
Bounding the animation
By default the elements will fly-in from the edge of the email. However if you’d prefer to have the fly-in effect from the edges of say a hero box, then add overflow: hidden to the bounding area.
On iOS, if you want an element to fly in from the right, you would need to wrap the animation within a bounding area with overflow set to hidden as well. Otherwise iOS will zoom out the email to display the initial location of the element “flying in” from the right.
The pop-in effect is a combination of a fade-in and a quick grow and shrink animation. It uses the opacity style to fade in and the scale 2D transform to start the scaling from 75% of its size to 120% back to 100% to deliver the “pop”. Using the scale 2D transform vs using widths and heights – as mentioned in the last section allows the element to grow and shrink without affecting its surrounding elements.
As you can see from the code below, there’s a significant time where the animation does “nothing” from 0-93%. That is so that we can spring the animation at the close to 2 second point. Modify these values to suit your needs. You can also use the animation-delay property subject to the caveats mentioned in the previous section.
Where to learn more
Aside from getting some of the basics of using animation in email in the last article, here are some other resources you can use.