CSS animation Property

Beginner
⏱️ 8 min read
📚 Updated: Jun 2026
🎯 4 Examples
Animations & Keyframes

What You’ll Learn

The animation property is a shorthand that applies CSS animations in one line. You define motion with @keyframes, then use animation to set name, duration, timing, and more.

01

Shorthand

One line, many settings.

02

@keyframes

Define animation steps.

03

Syntax Order

Name, duration, timing…

04

Duration

How long it runs.

05

Timing & Delay

Speed curve and wait time.

06

Repeat & Direction

Loop and playback control.

Definition and Usage

The animation CSS property is a shorthand for animation-related longhand properties. Instead of writing animation-name, animation-duration, and several others separately, you can combine them into one declaration.

Animations always need two parts: first define the keyframe steps with @keyframes, then apply them with animation. This makes it easier to create loaders, entrances, hover effects, and other dynamic UI motion.

💡
Beginner Tip

A minimal working animation usually needs at least a keyframe name and a duration, for example animation: fadeIn 1s;.

📝 Syntax

The animation shorthand accepts multiple values in a specific order:

syntax.css
selector {
  animation: name duration timing-function delay iteration-count direction fill-mode play-state;
}

Basic Example

animation.css
@keyframes moveAndColor {
  from {
    background-color: red;
    transform: translateX(0);
  }
  to {
    background-color: blue;
    transform: translateX(200px);
  }
}

.animated-box {
  animation: moveAndColor 3s ease-in-out 1s infinite alternate;
}

Syntax Rules

  • The first value is the @keyframes name, or none to disable animation.
  • When a duration is included, it must come immediately after the name.
  • Omitted values use their defaults: ease, 0s delay, 1 iteration, normal direction.
  • You can use animation: fadeIn 1s; for a simple one-time entrance effect.
  • Comma-separated lists apply multiple animations to the same element.

⚡ Quick Reference

QuestionAnswer
Initial valuenone 0s ease 0s 1 normal none running
Applies toAll elements
InheritedNo
AnimatableNo
Common useLoaders, entrances, attention cues, and interactive UI motion

Default Value

The initial value of animation is equivalent to:

animation-default.css
animation: none 0s ease 0s 1 normal none running;

This means no animation runs until you assign a keyframe name and a duration greater than zero.

💎 Property Values

Each part of the shorthand maps to a longhand animation property.

Shorthand partExampleLonghand property
namefadeInanimation-name
duration2s, 500msanimation-duration
timing-functionease-in-out, linearanimation-timing-function
delay0.5s, 1sanimation-delay
iteration-count3, infiniteanimation-iteration-count
directionnormal, alternateanimation-direction
fill-modeforwards, bothanimation-fill-mode
play-staterunning, pausedanimation-play-state
fadeIn 1s

A short shorthand with only the keyframe name and duration.

animation: fadeIn 1s;

Other values use browser defaults.

move 2s ease-in-out infinite alternate

Adds timing, repeat count, and direction for looping motion.

animation: move 2s ease-in-out infinite alternate;

Great for sliding and bouncing effects.

moveAndColor 3s ease-in-out 1s infinite alternate

Includes a 1 second delay before the animation starts repeating.

animation: moveAndColor 3s ease-in-out 1s infinite alternate;

Matches the reference example pattern.

bounce 1s ease-in-out infinite

A simple repeating bounce using only name, duration, timing, and iteration.

animation: bounce 1s ease-in-out infinite;

Useful for attention-grabbing UI cues.

How @keyframes Works with animation

Every CSS animation needs two steps working together:

StepCSS ruleRole
1. Define@keyframes slideUp { ... }Creates the animation steps and property changes over time
2. Applyanimation: slideUp 0.6s ease-out;Attaches the keyframes to an element with timing settings
3. Refineanimation-fill-mode: forwards;Optional longhand tweaks when shorthand is not enough

Shorthand vs Longhand

ApproachExampleWhen to use
Shorthandanimation: fadeIn 1s ease-out forwards;Most common animations in one readable line
Longhandanimation-name: fadeIn; plus separate propertiesWhen you need to change one setting independently in CSS or JS

Both approaches produce the same result. The shorthand is faster to write; longhand properties are easier to override one at a time.

👀 Live Preview

This box uses the full shorthand animation: moveAndColor 3s ease-in-out 0.5s infinite alternate;:

The box changes color, slides horizontally, waits briefly, then alternates direction on each repeat.

Examples Gallery

Try the animation shorthand with color and movement, simple fades, multiple animations, and longhand equivalents.

📚 Shorthand Basics

Start with one-line animations after defining your keyframes.

Example 1 — Animate Color and Movement

Animate a box to change background color and move horizontally with a delayed, infinite alternate loop.

animation-move-color.html
<style>
  @keyframes moveAndColor {
    from {
      background-color: red;
      transform: translateX(0);
    }
    to {
      background-color: blue;
      transform: translateX(200px);
    }
  }
  .animated-box {
    width: 100px;
    height: 100px;
    animation: moveAndColor 3s ease-in-out 1s infinite alternate;
  }
</style>

<div class="animated-box"></div>
Try It Yourself

How It Works

The shorthand sets name, duration, timing, delay, iteration count, and direction in one declaration.

Example 2 — Simple Fade-In Animation

Use a minimal shorthand when you only need a name and duration.

animation-fade.css
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.card {
  animation: fadeIn 0.8s ease-out forwards;
}
Try It Yourself

How It Works

forwards keeps the final keyframe styles after the animation finishes.

⚡ Multiple & Longhand

Combine multiple animations or expand the shorthand into separate properties.

Example 3 — Multiple Animations on One Element

Apply two animations with a comma-separated shorthand list.

animation-multiple.css
.badge {
  animation:
    fadeIn 0.5s ease-out forwards,
    pulse 1.2s ease-in-out 0.5s infinite;
}
Try It Yourself

How It Works

Each comma-separated group runs its own keyframe animation with its own timing settings.

Example 4 — Shorthand vs Longhand Equivalent

These two approaches produce the same spinner animation.

animation-longhand.css
/* Shorthand */
.spinner {
  animation: spin 1s linear infinite;
}

/* Longhand equivalent */
.spinner-longhand {
  animation-name: spin;
  animation-duration: 1s;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
}
Try It Yourself

How It Works

Use shorthand for brevity and longhand when you need to override one animation setting later.

🧠 How the animation Property Works

1

Define @keyframes

Write the animation steps under a custom name such as fadeIn or slideUp.

Define
2

Apply the shorthand

Set animation: fadeIn 1s ease-out; on the element you want to animate.

Apply
3

Browser runs the cycle

The browser interpolates property values over the duration using your timing function and repeat settings.

Animate
=

Animated UI

Elements move, fade, scale, or change color based on your keyframes and shorthand settings.

Universal Browser Support

The animation shorthand is supported in all modern browsers alongside @keyframes.

Baseline · CSS Animations

Create animations in modern browsers

Chrome, Firefox, Safari, Edge, and Opera all support the animation shorthand and keyframe animations.

98% Modern browser support
Google Chrome43+ · Desktop & Mobile
Full support
Mozilla Firefox16+ · Desktop & Mobile
Full support
Apple Safari9+ · macOS & iOS
Full support
Microsoft Edge12+ · Modern versions
Full support
Opera30+ · Modern versions
Full support

Legacy browsers

Very old browsers without CSS animation support cannot use the animation shorthand.

💻
Internet Explorer IE 9 and earlier · No CSS animation support
None
animation property 98% supported

Bottom line: Define clear keyframes and pair them with a duration in the animation shorthand for reliable results.

Conclusion

The animation property is the fastest way to apply CSS animations. Define your keyframes once, then use the shorthand to set duration, timing, delay, repetition, and direction.

Start with simple values like animation: fadeIn 1s;, then expand to fuller declarations such as animation: moveAndColor 3s ease-in-out 1s infinite alternate; as your effects become more advanced.

💡 Best Practices

✅ Do

  • Define reusable @keyframes with descriptive names
  • Always include a duration in the shorthand
  • Use forwards for one-time entrance animations
  • Prefer transform and opacity for smooth performance
  • Respect prefers-reduced-motion for accessibility

❌ Don’t

  • Forget to create matching @keyframes before applying animation
  • Put duration before the animation name
  • Animate too many properties at once without testing performance
  • Rely on animation alone for essential content visibility
  • Use overly long infinite animations that distract users

Key Takeaways

Knowledge Unlocked

Five things to remember about the animation property

Use these points when writing CSS animations.

5
Core concepts
📝02

Needs @keyframes

Define steps before applying.

Rule
⏱️03

Name + Duration

Minimum for visible motion.

Syntax
🔀04

Order Matters

Duration follows the name.

Rule
📈05

Multiple Values

Comma lists run several animations.

Pattern

❓ Frequently Asked Questions

The animation property is a shorthand that sets multiple animation-related properties in one declaration, including name, duration, timing function, delay, iteration count, direction, fill mode, and play state.
The initial value is equivalent to animation: none 0s ease 0s 1 normal none running, which means no animation runs until you assign keyframes and a duration.
Yes. The animation shorthand applies an animation to an element, but you must define the keyframe steps separately with @keyframes unless you use animation: none.
The usual order is name, duration, timing-function, delay, iteration-count, direction, fill-mode, and play-state. Duration must come immediately after the name when both are present.
Yes. You can list multiple comma-separated animation values, and each group pairs with the corresponding keyframe name and settings in the same order.

Practice in the Live Editor

Open the HTML editor, write @keyframes, and apply them with the animation shorthand.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful