📖 Deeper dive reading: MDN Animation
Using CSS to animate your components is an easy way to make your application feel alive and interactive. You create CSS animations using the animation properties and defining keyframes for what the element should look like at different times in the animation. Let's walk through an example.
We have a paragraph of centered text and we want it to zoom in until its size is 20% of the view height.
p {
text-align: center;
font-size: 20vh;
}To make this happen we specify that we are animating the selected elements by adding the animation-name property with a value of demo. This name refers to the name of the keyframes that we will specify in a minute. The keyframes tell what CSS properites should be applied at different key points in the animation sequence. We also add an animation-duration property in order to specify that the animation should last for three seconds.
p {
text-align: center;
font-size: 20vh;
animation-name: demo;
animation-duration: 3s;
}Now we are ready to create the keyframes. We don't have to define what happens at every millisecond of the animation. Instead we only need to define the key points, and CSS will generate a smooth transition to move from one keyframe to another. In our case we simply want to start with text that is invisible and have it zoom into the full final size. We can do this with two frames that are designated with the keywords from and to.
@keyframes demo {
from {
font-size: 0vh;
}
to {
font-size: 20vh;
}
}That's everything we need to do. However, let's make one more addition. It would look better if towards the end, the paragraph bounced out a little bigger than its final size. We can accommodate that by adding another key frame that happens 95 percent through the animation.
@keyframes demo {
from {
font-size: 0vh;
}
95% {
font-size: 21vh;
}
to {
font-size: 20vh;
}
}You can see this animation working with this CodePen.
Animation is not just for pushing buttons or making text float around. Here is an example of animating a watch using only HTML and CSS.
CodePen has a lot of CSS animation examples that you can experiment with. Here is a simple one with floating clouds that I found interesting. If you find an interesting one share it with us on Discord.

