CSS animation Property

Beginner
7 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The animation property plays a @keyframes sequence on an element. One line can set how long it runs, how it eases, and whether it repeats or stays at the end.

It is a shorthand for animation-name, animation-duration, animation-timing-function, animation-delay, animation-iteration-count, animation-direction, animation-fill-mode, and animation-play-state. It applies to all elements and is not inherited.

Standard-track.

Not deprecated. The shorthand has been widely available since 2015. A scroll animation-timeline inside animation is not reliable: Chrome only resets it, and other browsers can drop the whole declaration.

CSS Syntax

syntax.css
animation: 1s ease-in-out infinite alternate fade;

The first time is the duration. A second time is the delay. Put the @keyframes name last.

Property Values

Any piece you leave out uses its initial value. The initial animation is none, with a duration of 0s.

ValueDescriptionTry it
1sDuration. The first time value. 0s runs, but you cannot see itTry it
ease-in-outEasing. Slow at both ends. The initial easing is easeTry it
infiniteRepeat count. A number such as 3 plays that many times. The initial count is 1Try it
1s 1sDelay. The second time value waits before the animation startsTry it
alternateDirection. Every other play runs backward. The initial direction is normalTry it
forwardsFill mode. Keeps the last keyframe. Without it, the element snaps backTry it
pausedPlay state. Freezes the animation. The initial state is runningTry it
noneNo animation. This is the initial nameTry it

How to Use animation

Name the steps, then point animation at that name with a duration you can see.

  1. Write @keyframes fade with a from and a to.
  2. Set a duration longer than 0s. That first time value is how long one play lasts.
  3. Put the keyframe name last: animation: 1s fade;
  4. Add a count, alternate, or forwards only when you need it.
PieceRequired?Role
@keyframesYesThe named steps the shorthand plays
A durationYes, to see itThe first time. 0s is invisible
The name, lastYesWhich @keyframes to run

Live Preview

The word fades from full opacity to a quarter. Choose how animation plays that fade.

Apply again to replay a one-shot fade.

Result

Fade

animation: 1s fade

CSS Examples

Each snippet fades one word. The only change is the animation line. Use Try It Yourself for a live editor.

Example 1 — Play Once

The word fades for one second, then returns.

CSS
<style>
  @keyframes fade {
    from {
      opacity: 1;
    }

    to {
      opacity: 0.25;
    }
  }

  p {
    animation: 1s fade;
  }
</style>

<p>Fade</p>
Try It Yourself

How It Works

  1. Name the steps. @keyframes fade moves opacity from 1 to 0.25.
  2. Point at that name. animation: 1s fade plays fade for one second.
  3. One play. The count is 1 unless you set another number or infinite.
  4. It returns. Fill mode is none, so the word jumps back to full opacity when the second ends.

Example 2 — Fade Out and Back

The word keeps fading out, then back in.

CSS
<style>
  @keyframes fade {
    from {
      opacity: 1;
    }

    to {
      opacity: 0.25;
    }
  }

  p {
    animation: 1s infinite alternate fade;
  }
</style>

<p>Fade</p>
Try It Yourself

How It Works

  1. Use the same steps. fade still goes from full opacity to a quarter.
  2. Repeat. infinite plays it again as soon as one second ends.
  3. Turn around. alternate runs the next play backward, from dim back to full.
  4. Without alternate. Each new play would jump to the start, then fade out again.

Example 3 — Stay at the End

The word fades once and remains dim.

CSS
<style>
  @keyframes fade {
    from {
      opacity: 1;
    }

    to {
      opacity: 0.25;
    }
  }

  p {
    animation: 1s forwards fade;
  }
</style>

<p>Fade</p>
Try It Yourself

How It Works

  1. Play the fade. One second, from opacity 1 to 0.25.
  2. Keep the last frame. forwards holds the to style after the play ends.
  3. The count is still one. Nothing here says infinite.
  4. Drop forwards and it snaps. Fill mode none throws away the animated opacity and restores the normal style.

Edge Cases & Pitfalls

If nothing moves, the time or the name is usually the reason.

0s

No duration means nothing to see

animation: fade uses the initial duration, 0s. The animation still starts and ends, but the fade is invisible.

time

The first time is the duration

animation: 1s 2s fade plays for 1 second after a 2 second wait. The second time is the delay.

name

Put the keyframe name last

A value that can be a keyword, such as ease or forwards, is taken by that piece. A custom name at the end is left for @keyframes.

end

It snaps back unless you say forwards

The initial fill mode is none. The element keeps the last keyframe only when the shorthand includes forwards or both.

motion

Some people need the motion turned off

A fast loop can be hard to read. prefers-reduced-motion is how a visitor asks for less motion. Do not put an animation-timeline keyword in this shorthand. Set that property on its own line after animation.

Browser Support

animation is a browser style property. Node.js, Deno, and Bun do not play it. The versions below are the unprefixed shorthand.

✓ Baseline · Widely available since 2015

animation

Chrome 43+, Firefox 16+, Safari 9+, Edge 12+, Internet Explorer 10+. A timeline keyword inside the shorthand is a separate, newer feature.

97% unprefixed shorthand
Google Chrome 43+
Full support
Mozilla Firefox 16+
Full support
Apple Safari 9+
Full support
Microsoft Edge 12+
Full support
Opera 30+
Full support
Samsung Internet 4+
Full support
Internet Explorer 10+
Full support
animation Widely supported

Bottom line: Older Chrome, Safari, and Firefox also accepted a prefixed shorthand. Putting animation-timeline inside animation is Chrome 115 reset-only, and Firefox and Safari do not support that keyword here.

Key Takeaways

  • Role: one shorthand that plays a named @keyframes sequence.
  • Time: the first time is the duration. The second time is the delay.
  • Name last: animation: 1s infinite alternate fade.
  • forwards: keep the last frame. Without it, the element snaps back.

One line: define @keyframes, then play it with a duration and the name at the end.

Frequently Asked Questions

It plays a named @keyframes sequence on an element. One declaration can set the duration, easing, delay, repeat count, direction, fill mode, and play state.
Yes. animation only points at a name. The steps live in @keyframes with that same name. animation: none turns the animation off.
The initial fill mode is none, so the element returns to its normal style when the animation ends. Add forwards to keep the last keyframe.
The first time is the duration. The second time is the delay. animation: 1s 2s fade plays for 1 second after waiting 2 seconds.
Chrome 43+, Firefox 16+, Safari 9+, Edge 12+, and Internet Explorer 10 support the unprefixed shorthand. It is a browser style property, not a Node.js feature.

Next: animation-delay

Set the wait on its own, without rewriting the rest of the shorthand.

animation-delay tutorial →

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.

8 people found this page helpful