CSS Reference ยท Transforms, Transitions and Animations
The animation-name property
Reference for the CSS animation-name property: attach one or more @keyframes rules to an element, with syntax, naming rules, live examples and support.
The animation-name property says which @keyframes rule an element should play. It is the link between the element and the animation steps. Without a name, or with a name that matches no @keyframes, nothing animates.
Setting a name is not enough on its own: you also need a non-zero animation-duration.
@keyframes slide-in { from { transform: translateX(-100%); } to { transform: translateX(0); } } .drawer { animation-name: slide-in; animation-duration: 400ms; }
Try it
The first name pairs with the first duration (2s), the second name with the second (3s). Since animation-iteration-count and the other lists have one value, it applies to both.
Syntax
animation-name: [ none | <keyframes-name> ]#
<keyframes-name> = <custom-ident> | <string>
- Initial value:
none - Applies to: all elements, and the
::beforeand::afterpseudo-elements - Inherited: no
- Animatable: no
- Computed value: as specified
Values
| Value | Description |
|---|---|
none |
No animation. Also a way to cancel an animation set by a less specific rule. |
<custom-ident> |
The name of an @keyframes rule, for example slide-in. Case-sensitive. |
<string> |
A quoted name, which allows names that would otherwise clash with keywords. |
| Comma-separated list | Several animations at once; other animation properties line up with the list by position. |
Usage notes
- Names are case-sensitive.
Fadeandfadeare different keyframes. - Avoid keyword names. Do not call a keyframes rule
none,initial,inherit,unsetordefault; they are reserved. Names such asinfiniteoreaseare also a bad idea when you use theanimationshorthand. - No match, no animation. A typo in the name fails silently. Check the name first when an animation does not run.
- Last rule wins. If several
@keyframesrules share a name, the last one defined is used; they are not merged. - Overlapping properties. When two named animations animate the same property, the later one in the list wins for that property (unless you set
animation-composition). - Restarting. Changing
animation-nameto another value starts the new animation from the beginning. Removing the name and adding it again is a common (if hacky) way to replay an animation.
Browser support
Supported in every browser.
Related
animationโ the shorthand@keyframesโ defines the stepsanimation-durationโ required for visible motionanimation-compositionโ how overlapping animations combine- Lesson: Animations