CSS3 animation-timing-function property
Example
Play the animation at the same speed from start to finish:
animation-timing-function
:linear
; -
webkit-animation-timing-function
:linear
;
/*
Safari and Chrome
*/
Try it »
There are more examples at the bottom of this page.
Browser support
| property | |||||
|---|---|---|---|---|---|
| animation-timing-function | 43.0 | ||||
| 4.0 -webkit- | 10.0 | 16.0 | |||
| 5.0 -moz- | 9.0 | ||||
| 4.0 -webkit- | 30.0 |
15.0 -webkit-
12.0 -o- |
Tag Definition and Usage Notes
The animation-timing-function specifies how an animation will complete a cycle.
The speed curve defines the time an animation takes to change from one set of CSS styles to another.
The speed curve is used to make the changes smoother.
| Default value: | ease |
|---|---|
| Inherited: | no |
| Version: | CSS3 |
| JavaScript syntax: | object object.style.animationTimingFunction="linear" |
Syntax
animation-timing-function:
value
;
The animation-timing-function uses a mathematical function called a cubic Bezier curve as the speed curve. With this function, you can use your own values or one of the predefined values:
| Value | Description | Testing |
|---|---|---|
| linear | The animation has the same speed from start to end. | Testing |
| ease | Default. The animation starts at a low speed, then speeds up, and slows down before ending. | Testing |
| ease-in | The animation starts at a low speed. | Testing |
| ease-out | The animation ends at a low speed. | Testing |
| ease-in-out | The animation starts and ends at a low speed. | Testing |
| steps(int,start|end) |
Specifies the number of intervals (steps) in the timing function. There are two parameters: the first specifies the number of intervals of the function and must be a positive integer (greater than 0). The second parameter is optional and indicates whether the animation is continuous from the beginning or the end of the period. The meanings are as follows: |
Tip: Try using different values in the "Try it" feature below.
Online example
Example
To better understand the different timing function values, here are five different div elements set with five different values:
/*
Chrome, Safari, and Opera
*/
#div1
{
webkit-animation-timing-function:
linear
;
}
#div2
{
webkit-animation-timing-function:
ease
;
}
#div3
{
webkit-animation-timing-function:
ease-in
;
}
#div4
{
webkit-animation-timing-function:
ease-out
;
}
#div5
{
webkit-animation-timing-function:
ease-in-out
;
}
/*
Standard syntax
*/
#div1
{
animation-timing-function:
linear
;
}
#div2
{
animation-timing-function:
ease
;
}
#div3
{
animation-timing-function:
ease-in
;
}
#div4
{
animation-timing-function:
ease-out
;
}
#div5
{
animation-timing-function:
ease-in-out
;
}
Try it »
Example
Same as the previous example, but the speed curve is defined by a cubic-bezier function:
#div1
{
animation-timing-function:
cubic-bezier
(
0
,
0
,
0.25
,
1
)
;
}
#div2
{
animation-timing-function:
cubic-bezier
(
0.25
,
0.1
,
0.25
,
1
)
;
}
#div3
{
animation-timing-function:
cubic-bezier
(
0.42
,
0
,
1
,
1
)
;
}
#div4
{
animation-timing-function:
cubic-bezier
(
0
,
0
,
0.58
,
1
)
;
}
#div5
{
animation-timing-function:
cubic-bezier
(
0.42
,
0
,
0.58
,
1
)
;
}
/*
Safari and Chrome:
*/
#div1
{
webkit-animation-timing-function:
cubic-bezier
(
0
,
0
,
0.25
,
1
)
;
}
#div2
{
webkit-animation-timing-function:
cubic-bezier
(
0.25
,
0.1
,
0.25
,
1
)
;
}
#div3
{
webkit-animation-timing-function:
cubic-bezier
(
0.42
,
0
,
1
,
1
)
;
}
#div4
{
webkit-animation-timing-function:
cubic-bezier
(
0
,
0
,
0.58
,
1
)
;
}
#div5
{
webkit-animation-timing-function:
cubic-bezier
(
0.42
,
0
,
0.58
,
1
)
;
}
Try it »
Related Articles
CSS3 tutorial: CSS3 Animations