Intermediate Topic 23 of 51 Web Development
CSS Animations
Declarative motion through transitions and keyframes.
How it works
CSS animations and transitions animate property changes without JavaScript. A transition smoothly interpolates between two states when a property changes, specified with duration, timing function and delay. Keyframe animations define named sequences with @keyframes and are applied with the animation properties for repeating, direction and fill mode. Animating transform and opacity is cheap because they can run on the GPU compositor without layout.
Step-by-step walkthrough
- A transition animates a change between two states.
- For example opacity 0 to 1 over 300ms.
- Keyframes define several steps in an animation.
- Prefer animating transform and opacity, which are cheap.
- Respect prefers-reduced-motion.
Where it is used
Hover effects, loading spinners, page transitions, attention cues and micro-interactions use CSS animation. The Web Animations API offers programmatic control.
Common pitfall
Animating layout properties such as width, height or top triggers expensive reflow and jank. Excessive motion can cause discomfort or dizziness, so respect prefers-reduced-motion. Long, flashy animations slow users down. Use will-change sparingly, test performance on low-end devices and animate to communicate state, not for decoration.
Where it fits in the course
CSS Animations is topic 23 of 51 in Web Development, rated Intermediate. It follows Local Storage and Cookies. The next topic is Web Accessibility.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Web Development quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Web Development quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is CSS Animations?
Where do people use CSS Animations?
What is the most common mistake with CSS Animations?
What should I learn before this topic?
How can I practice it?
Is CSS Animations hard to learn?
How long does it take to learn CSS Animations?
Which topics are related to CSS Animations?
What should I study after CSS Animations?
Related topics
- Local Storage and Cookies (Web Development)
- Web Accessibility (Web Development)
- ES Modules (Web Development)
- ARIA (Web Development)