animation-name
Specifies which @keyframes an element plays.
- Initial value
none- Inherited
- No
- Animatable
- no
- Applies to
- all elements and the ::before and ::after pseudo-elements
- JavaScript
element.style.animationName = "slide"
Example
#.badge {
animation-name: pop;
animation-duration: 0.6s;
}
@keyframes pop {
from { transform: scale(0.6); opacity: 0; }
to { transform: scale(1); opacity: 1; }
}<p><span class="badge box" style="display:inline-grid">New</span></p>Definition and usage
#The animation-name property links an element to an animation defined in an @keyframes rule. The name alone is not enough: the animation only starts when it also has a duration (animation-duration) greater than zero.
You can provide several comma-separated names. Each animation then runs in parallel, and the other animation properties (duration, delay, iteration count) are matched to the names in the list in order.
If the name does not match any @keyframes rule, nothing happens and the browser reports no error. When an animation โdoes not workโ, check the spelling first.
Syntax
#animation-name: none | keyframes-name [, keyframes-name]*;Values
#- No animation. Useful for turning off an animation inherited from another rule.
keyframes-name
The name of your own@keyframesrule. Here the element moves to the right and back.keyframes-name
Another@keyframesrule: the element pulses and changes color.list of names
Two animations at once. Both run in parallel and their transforms override each other, so the last one in the list wins.
Values in practice
#none
.demo .box { animation-name: none; }slide
@keyframes rule. Here the element moves to the right and back..demo .box { animation-name: slide; }pulse
@keyframes rule: the element pulses and changes color..demo .box { animation-name: pulse; }slide, spin
.demo .box { animation-name: slide, spin; }Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- Give keyframes descriptive names, such as
fade-inorslide-up. They are easier to find in the stylesheet. - Respect the system setting that reduces motion: turn animations off or shorten them inside
@media (prefers-reduced-motion: reduce).
Related entries
#Spotted a mistake or missing an example? Write to us.