Skip to content
Tutorials Center
My learning

Topics

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.

CSS
@keyframes slide-in {
  from { transform: translateX(-100%); }
  to   { transform: translateX(0); }
}

.drawer {
  animation-name: slide-in;
  animation-duration: 400ms;
}

Try it

Two animations on one element

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

CSS
animation-name: [ none | <keyframes-name> ]#

<keyframes-name> = <custom-ident> | <string>
  • Initial value: none
  • Applies to: all elements, and the ::before and ::after pseudo-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. Fade and fade are different keyframes.
  • Avoid keyword names. Do not call a keyframes rule none, initial, inherit, unset or default; they are reserved. Names such as infinite or ease are also a bad idea when you use the animation shorthand.
  • 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 @keyframes rules 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-name to 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.