CSS animation-name Property
The animation-name property specifies the name of one or more @keyframes rules used to animate an element.
Each name connects an element to a keyframe definition that describes how its CSS properties change. You can apply one animation, combine several animations, or use none to disable a named animation.
animation-name Syntax
selector {
animation-name: fade-in;
}
The name must match an existing @keyframes rule for that animation to produce an effect.
.fade {
animation-name: fade-in;
}
.slide {
animation-name: slide-in;
}
.no-animation {
animation-name: none;
}
.multiple {
animation-name: fade-in, slide-in;
}
Animation names can also be written as quoted strings, although unquoted identifiers are generally preferred.
.box {
animation-name: "fade-in";
}
The property also accepts the global CSS values inherit, initial, revert, revert-layer, and unset.
Property Values
| Value | Description |
|---|---|
none |
Specifies that no keyframe animation is applied. This is the initial value. |
fade-in |
References a @keyframes rule named fade-in. |
"fade-in" |
References a keyframe animation using a quoted string name. |
fade-in, slide-in |
Specifies two animations to apply to the same element. |
none, rotate |
Disables the first animation entry while retaining the second named animation. |
Animation names use the CSS <custom-ident> or <string> syntax. Unquoted identifiers are case-sensitive and cannot use reserved CSS-wide keywords or none as animation names.
The property applies to all elements, including the ::before and ::after pseudo-elements, is not inherited, and has an initial value of none.
Its computed value is the specified list of animation names, and the property itself is not animatable.
How animation-name Works
A CSS keyframe animation requires a @keyframes rule defining the changes and an animation declaration connecting those keyframes to an element.
@keyframes fade-in {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
.box {
animation-name: fade-in;
animation-duration: 2s;
animation-fill-mode: forwards;
}
The browser finds the @keyframes fade-in rule and applies its keyframe effects to the element over two seconds.
The animation-name property identifies the animation. Other animation properties control its duration, delay, timing function, direction, iteration count, and fill behavior.
If no matching @keyframes rule exists, the named animation produces no keyframe effects.
For ordinary time-based animations, specify a nonzero animation-duration to make the transition between keyframes visible.
Naming Keyframe Animations
Names assigned to @keyframes rules are case-sensitive. The value of animation-name must match the keyframe name exactly.
@keyframes slide-in {
from {
transform: translateX(-100px);
}
to {
transform: translateX(0);
}
}
.panel {
animation-name: slide-in;
animation-duration: 1s;
}
In this example, the element references the slide-in keyframes correctly.
Changing the declaration to animation-name: Slide-In; would not match the lowercase slide-in definition.
Choosing Animation Names
Use descriptive names that explain the effect, such as fade-in, slide-left, rotate-icon, or pulse-button.
Avoid generic names that could conflict with animations used elsewhere in the stylesheet.
Duplicate Keyframe Names
If multiple @keyframes rules with the same name apply within the same style origin and cascade layer, the last applicable rule is used. Their individual keyframes are not combined into one definition.
Use unique names when separate animations should remain independent.
Using the none Value
The none keyword indicates that no keyframe animation is associated with that animation entry.
.box {
animation-name: fade-in;
animation-duration: 2s;
}
.box.no-animation {
animation-name: none;
}
When the no-animation class is added, the named animation is removed and its keyframe effects no longer apply.
The none value can also appear in a list of animation names.
.box {
animation-name: none, rotate;
animation-duration: 1s, 3s;
}
The first entry does not animate, while the second references the rotate keyframes and uses the three-second duration.
This allows individual animation positions to be disabled without changing the ordering of the remaining animation settings.
Multiple Animation Names
You can apply several named animations to the same element by separating their names with commas.
.animated-element {
animation-name: fade-in, slide-in;
animation-duration: 1s, 2s;
animation-timing-function: ease, ease-out;
animation-fill-mode: forwards, forwards;
}
The first animation uses the fade-in keyframes and lasts one second. The second uses slide-in and lasts two seconds.
Animation property values are matched to names in their listed order.
If fewer values are provided for another animation property, the browser repeats that property's list as needed.
.box {
animation-name: fade, move, rotate;
animation-duration: 1s, 2s;
}
Here, fade uses 1s, move uses 2s, and rotate uses 1s.
When multiple animations affect the same CSS property, the animation composition and ordering rules determine the resulting effect. With the default replace composition, the later animation in the list generally takes precedence when effects overlap.
animation-name Example
The following example uses three named keyframe animations to demonstrate horizontal movement, fading, and rotation.
<div class="name-demo">
<div class="name-row">
<strong>slide</strong>
<div class="name-track"><div class="name-box slide"></div></div>
</div>
<div class="name-row">
<strong>fade</strong>
<div class="name-track"><div class="name-box fade"></div></div>
</div>
<div class="name-row">
<strong>rotate</strong>
<div class="name-track"><div class="name-box rotate"></div></div>
</div>
</div>
.name-demo {
display: grid;
gap: 12px;
}
.name-row {
display: flex;
align-items: center;
gap: 12px;
}
.name-row strong {
flex: 0 0 55px;
}
.name-track {
flex: 1;
min-width: 0;
height: 44px;
padding: 7px;
background-color: #f1f3f5;
border: 1px solid #ccc;
box-sizing: border-box;
}
.name-box {
width: 28px;
height: 28px;
background-color: #1769aa;
animation-duration: 2s;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
animation-direction: alternate;
}
.name-box.slide {
animation-name: name-slide;
}
.name-box.fade {
animation-name: name-fade;
}
.name-box.rotate {
animation-name: name-rotate;
}
@keyframes name-slide {
from {
transform: translateX(0);
}
to {
transform: translateX(100px);
}
}
@keyframes name-fade {
from {
opacity: 1;
}
to {
opacity: 0.2;
}
}
@keyframes name-rotate {
from {
transform: rotate(0deg);
}
to {
transform: rotate(180deg);
}
}
@media (prefers-reduced-motion: reduce) {
.name-box {
animation: none;
}
}
Each square uses the same duration, timing function, iteration count, and direction. Only the animation-name value changes, selecting a different set of keyframes.
The first square moves horizontally, the second fades between two opacity values, and the third rotates. Each effect is selected by its matching animation name.
All three animations repeat continuously. If reduced motion is enabled, the squares remain stationary.
Using the animation Shorthand
The animation-name property can be specified separately or included in the animation shorthand.
For example, these declarations:
.box {
animation-name: fade-in;
animation-duration: 2s;
animation-timing-function: ease;
animation-iteration-count: 1;
animation-fill-mode: forwards;
}
Can be written as:
.box {
animation: 2s ease 1 forwards fade-in;
}
Placing the animation name at the end of the shorthand is recommended because some keywords can also represent other animation properties.
For example, reverse is recognized as an animation direction. Using it as an unquoted name in the shorthand can produce an unexpected result.
The shorthand also resets animation properties that are not explicitly included. If a separate animation-name declaration should override the shorthand, place it afterward or give it higher cascade priority.
Important Considerations
Keep the following points in mind when using animation-name:
- Matching names: The name must match an existing
@keyframesrule, including capitalization. - Default value: The initial value is
none, so no keyframe animation is selected by default. - Animation duration: For ordinary time-based animations, a nonzero duration is generally needed to see keyframes transition over time.
- Reserved keywords: Avoid CSS-wide keywords and
noneas unquoted animation names. - Multiple animations: Use comma-separated names and match other animation property values in the same order.
- Duplicate definitions: Avoid reusing a keyframe name for unrelated effects, since duplicate definitions can override one another.
- Pseudo-elements: Named animations can also be applied to
::beforeand::after. - Accessibility: Respect
prefers-reduced-motionand avoid relying on animation alone to communicate important information.
Use descriptive, consistent animation names to make keyframe definitions easier to maintain and reuse throughout a stylesheet.
Browser Support
The animation-name property has Baseline Widely available status and has been supported across major browser engines since September 2015, including Chrome, Edge, Firefox, and Safari.
Named keyframe animations and comma-separated animation lists are broadly supported. Older browser versions may require vendor-prefixed animation properties.
Visit Can I Use? to check current browser compatibility.
Specifications
The animation-name property is defined in the CSS Animations Level 1 specification.
