animation 346k2n
The animation property is a shorthand property for setting the longhand animation properties: 4v663t
animation-name
animation-duration
animation-timing-function
animation-delay
animation-iteration-count
animation-direction
animation-fill-mode
animation-play-state
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 3xs5l
- 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 u704t
- <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 2h2053
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 6b4m17
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.
Browser 572e63
CSS Animation 2x1m4x
Complex method of animating certain properties of an element
W3C Working Draft
ed from the following versions:
Desktop ea5q
- 43
- 16
- 10
- 12
- 9
Mobile / Tablet 6s2f12
- 9.0
- 66
- No
- 66
- 60
Notes 441w3q
In Chrome, the animation
shorthand property is ed prefixed with the -webkit-
prefix, while the longhand properties are ed unprefixed.