CSS Reference Property

animation 4j1ri

The animation property is a shorthand property for setting the longhand animation properties: 4f6w5r

It takes one or multiple comma-separated values, where each value calls and controls a @keyframes rule defines the actual animation sequence, and is controlled by the animation properties.

/* syntax of one animation definition */
animation: [animation-name] [animation-duration] [animation-timing-function] [animation-delay] [animation-iteration-count] [animation-direction] [animation-fill-mode] [animation-play-state];

/* two animation definitions */
animation: [animation-name] [animation-duration] [animation-timing-function] [animation-delay] [animation-iteration-count] [animation-direction] [animation-fill-mode] [animation-play-state],
           [animation-name] [animation-duration] [animation-timing-function] [animation-delay] [animation-iteration-count] [animation-direction] [animation-fill-mode] [animation-play-state];
                

The longhand properties are space-separated, and their order doesn’t matter except when using both <time> values in your definition, the first one will be considered the animation duration, and the second one will be considered the animation delay.

Any value that you don’t explicitly set will be set to its default value. That is why you have to specify an animation name otherwise no animation will be applied. If you don’t apply an animation duration, it will default to ‘0s’, and the animation effect occurs instantaneously and thus the keyframes have no effect.

Animations can be applied to only a subset of all CSS properties. The following are two resources listing the animatable properties in CSS:

Official Syntax 55184y

  • Syntax:

    animation: <single-animation># 
    /* where */
    <single-animation> = <time> || <single-timing-function> || <time> || <single-animation-iteration-count> || <single-animation-direction> || <single-animation-fill-mode> || <single-animation-play-state> || <single-animation-name>
  • Initial: none 0s ease 0s 1 normal none; which is the concatenation of the initial values of each of the longhand properties
  • Applies To: all elements; and ::after pseudo-elements
  • Animatable: no

Values 584j31

<single-animation>#
One or multiple comma-separated animation definitions, where each definition is defined using the longhand animation properties. See the longhand properties’ entries for more information about the possible values for each.

Examples 3e5p5z

The following are valid animation declarations:

/* one animation */
animation: bounce .3s ease-in-out 1s infinite;
animation: rotate-out 1s steps(3, end);
animation: .3s ease 1s reverse open-up;

/* multiple animations */
animation: shake .3s alternate,
           jump 1s cubic-bezier(.17,.67,.85,.06) alternate;
                

The animation: bounce .3s ease-in-out 1s infinite; declaration is equivalent to:

animation-name: bounce;
animation-duration: .3s;
animation-timing-function: ease-in-out;
animation-delay: 1s;
animation-iteration-count: infinite;
                

Live Demo 2x4j2k

The following example applies a ‘falling down’ effect to a piece of text using the shorthand animation property.

Check the @keyframes entry out for more information on how the animation effect is created, and for more examples of animations.

View this demo on the Codrops Playground

Browser k5t66

CSS Animation 4x1j4h

Complex method of animating certain properties of an element

W3C Working Draft

ed from the following versions:

Desktop 3n671n

  • 43
  • 16
  • 10
  • 12
  • 9

Mobile / Tablet 4q224p

  • 9.0
  • 66
  • No
  • 66
  • 60

* denotes prefix required.

  • ed:
  • Yes
  • No
  • Partially
  • Polyfill

Stats from caniuse.com

Notes z5jo

In Chrome, the animation shorthand property is ed prefixed with the -webkit- prefix, while the longhand properties are ed unprefixed.

Further Reading 4g1p1d

Written by

Last updated June 26, 2020 at 9:22 am by Mary Lou

Do you have a suggestion, question or want to contribute? Submit an issue.