CSS animation Property Explained
What the CSS animation property does, with an example.
Published November 5, 2026
The animation shorthand runs @keyframes sequences: animation: name duration timing delay iteration-count direction fill-mode. Unlike transitions, animations can loop and have multiple steps.
How it works
Define @keyframes with percentage steps, then attach it to an element. animation-fill-mode: forwards keeps the end state.
Animate transform and opacity to stay smooth.
Values and effects
animation: spin 1s linear infinite; → endless rotation
animation: fade-in .5s ease-out both; → play once, keep ends
animation: pulse 2s ease-in-out infinite alternate; → back and forth
Practical examples
Fade in
@keyframes fade-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.card { animation: fade-in .4s ease-out both; }Pulse
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.05); } }
.dot { animation: pulse 2s infinite; }Reduced motion
@media (prefers-reduced-motion: reduce) { .card { animation: none; } }Common mistakes
- Animating layout properties (width, top) causing jank.
- Forgetting animation-fill-mode so elements snap back.
- Ignoring reduced-motion preferences.
Key takeaways
- animation in one line: The animation shorthand runs @keyframes sequences: animation: name duration timing delay iteration-count direction fill-mode.
- Inspect it live in DevTools → Styles.
- Test across browsers and screen sizes.
FAQ
Animation vs transition?
Transitions go between two states on change; animations run keyframes on their own and can loop.
Is animation supported in all browsers?
Yes in all modern browsers; check caniuse.com for edge cases.