- CSS animation-timing-function Property
- Definition and Usage
- Browser Support
- CSS Syntax
- Property Values
- More Examples
- Example
- Example
- animation-timing-function
- Try it
- Syntax
- Values
- Description
- Formal definition
- Formal syntax
- Examples
- Cubic-Bezier examples
- Step examples
- Specifications
- Browser compatibility
- See also
- Found a content problem with this page?
- MDN
- Support
- Our communities
- Developers
CSS animation-timing-function Property
Play an animation with the same speed from beginning to end:
More «Try it Yourself» examples below.
Definition and Usage
The animation-timing-function specifies the speed curve of an animation.
The speed curve defines the TIME an animation uses to change from one set of CSS styles to another.
The speed curve is used to make the changes smoothly.
Default value: | ease |
---|---|
Inherited: | no |
Animatable: | no. Read about animatable |
Version: | CSS3 |
JavaScript syntax: | object.style.animationTimingFunction=»linear» Try it |
Browser Support
The numbers in the table specify the first browser version that fully supports the property.
Numbers followed by -webkit-, -moz-, or -o- specify the first version that worked with a prefix.
CSS Syntax
animation-timing-function: linear|ease|ease-in|ease-out|ease-in-out|step-start|step-end|steps(int,start|end)|cubic-bezier(n,n,n,n)|initial|inherit;
The animation-timing-function uses a mathematical function, called the Cubic Bezier curve, to make the speed curve. You can use your own values in this function, or use one of the pre-defined values:
Property Values
Value | Description | Demo |
---|---|---|
linear | The animation has the same speed from start to end | Play it » |
ease | Default value. The animation has a slow start, then fast, before it ends slowly | Play it » |
ease-in | The animation has a slow start | Play it » |
ease-out | The animation has a slow end | Play it » |
ease-in-out | The animation has both a slow start and a slow end | Play it » |
step-start | Equivalent to steps(1, start) | |
step-end | Equivalent to steps(1, end) | |
steps(int,start|end) | Specifies a stepping function, with two parameters. The first parameter specifies the number of intervals in the function. It must be a positive integer (greater than 0). The second parameter, which is optional, is either the value «start» or «end», and specifies the point at which the change of values occur within the interval. If the second parameter is omitted, it is given the value «end» | |
cubic-bezier(n,n,n,n) | Define your own values in the cubic-bezier function Possible values are numeric values from 0 to 1 | |
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
Tip: Try the different values in the «More Examples» section below.
More Examples
Example
To better understand the different timing function values;
Here are five different elements with five different values:
Example
Same as the example above, but the speed curves are defined with the cubic-bezier function:
animation-timing-function
The animation-timing-function CSS property sets how an animation progresses through the duration of each cycle.
Try it
It is often convenient to use the shorthand property animation to set all animation properties at once.
Syntax
/* Keyword values */ animation-timing-function: ease; animation-timing-function: ease-in; animation-timing-function: ease-out; animation-timing-function: ease-in-out; animation-timing-function: linear; animation-timing-function: step-start; animation-timing-function: step-end; /* Function values */ animation-timing-function: cubic-bezier(0.1, 0.7, 1, 0.1); animation-timing-function: steps(4, end); /* Steps Function keywords */ animation-timing-function: steps(4, jump-start); animation-timing-function: steps(10, jump-end); animation-timing-function: steps(20, jump-none); animation-timing-function: steps(5, jump-both); animation-timing-function: steps(6, start); animation-timing-function: steps(8, end); /* Multiple animations */ animation-timing-function: ease, step-start, cubic-bezier(0.1, 0.7, 1, 0.1); /* Global values */ animation-timing-function: inherit; animation-timing-function: initial; animation-timing-function: revert; animation-timing-function: revert-layer; animation-timing-function: unset;
Values
The easing function that corresponds to a given animation, as determined by animation-name .
The non-step keyword values (ease, linear, ease-in-out, etc.) each represent cubic Bézier curve with fixed four point values, with the cubic-bezier() function value allowing for a non-predefined value. The step easing functions divides the input time into a specified number of intervals that are equal in length. It is defined by a number of steps and a step position.
Equal to cubic-bezier(0.25, 0.1, 0.25, 1.0) , the default value, increases in velocity towards the middle of the animation, slowing back down at the end.
Equal to cubic-bezier(0.0, 0.0, 1.0, 1.0) , animates at an even speed.
Equal to cubic-bezier(0.42, 0, 1.0, 1.0) , starts off slowly, with the speed of the transition of the animating property increasing until complete.
Equal to cubic-bezier(0, 0, 0.58, 1.0) , starts quickly, slowing down the animation continues.
Equal to cubic-bezier(0.42, 0, 0.58, 1.0) , with the animating properties slowly transitioning, speeding up, and then slowing down again.
An author defined cubic-bezier curve, where the p1 and p3 values must be in the range of 0 to 1.
Displays an animation iteration along n stops along the transition, displaying each stop for equal lengths of time. For example, if n is 5, there are 5 steps. Whether the animation holds temporarily at 0%, 20%, 40%, 60% and 80%, on the 20%, 40%, 60%, 80% and 100%, or makes 5 stops between the 0% and 100% along the animation, or makes 5 stops including the 0% and 100% marks (on the 0%, 25%, 50%, 75%, and 100%) depends on which of the following jump terms is used:
Denotes a left-continuous function, so that the first jump happens when the animation begins;
Denotes a right-continuous function, so that the last jump happens when the animation ends;
There is no jump on either end. Instead, holding at both the 0% mark and the 100% mark, each for 1/n of the duration.
Includes pauses at both the 0% and 100% marks, effectively adding a step during the animation iteration.
Equal to steps(1, jump-start)
Note: When you specify multiple comma-separated values on an animation-* property, they are applied to the animations in the order in which the animation-name s appear. For situations where the number of animations and animation-* property values do not match, see Setting multiple animation property values.
Note: animation-timing-function has the same effect when creating CSS scroll-driven animations as it does for regular time-based animations.
Description
Easing functions may be specified on individual keyframes in a @keyframes rule. If no animation-timing-function is specified on a keyframe, the corresponding value of animation-timing-function from the element to which the animation is applied is used for that keyframe.
Within a keyframe, animation-timing-function is an at-rule-specific descriptor, not the property of the same name. The timing is not being animated. Rather, a keyframe’s easing function is applied on a property-by-property basis from the keyframe on which it is specified until the next keyframe specifying that property, or until the end of the animation if there is no subsequent keyframe specifying that property. As a result, an animation-timing-function specified on the 100% or to keyframe will never be used.
Formal definition
Formal syntax
animation-timing-function =
#
=
linear |
|
|
=
linear( )
=
ease |
ease-in |
ease-out |
ease-in-out |
cubic-bezier( , , , )
=
step-start |
step-end |
steps( [, ]? )
=
[ ]#
=
jump-start |
jump-end |
jump-none |
jump-both |
start |
end
=
&&
?
=
Examples
Cubic-Bezier examples
div class="parent"> div class="ease">easediv> div class="easein">ease-indiv> div class="easeout">ease-outdiv> div class="easeinout">ease-in-outdiv> div class="linear">lineardiv> div class="cb">cubic-bezier(0.2,-2,0.8,2)div> div>
.parent > div[class] animation-name: changeme; animation-duration: 10s; animation-iteration-count: infinite; margin-bottom: 4px; > @keyframes changeme 0% min-width: 12em; width: 12em; background-color: black; border: 1px solid red; color: white; > 100% width: 90vw; min-width: 24em; background-color: magenta; color: yellow; border: 1px solid orange; > >
.ease animation-timing-function: ease; > .easein animation-timing-function: ease-in; > .easeout animation-timing-function: ease-out; > .easeinout animation-timing-function: ease-in-out; > .linear animation-timing-function: linear; > .cb animation-timing-function: cubic-bezier(0.2, -2, 0.8, 2); >
Step examples
div class="parent"> div class="jump-start">jump-startdiv> div class="jump-end">jump-enddiv> div class="jump-both">jump-bothdiv> div class="jump-none">jump-nonediv> div class="start">startdiv> div class="end">enddiv> div class="step-start">step-startdiv> div class="step-end">step-enddiv> div>
.parent > div[class] animation-name: changeme; animation-duration: 10s; animation-iteration-count: infinite; margin-bottom: 4px; > @keyframes changeme 0% min-width: 12em; width: 12em; background-color: black; border: 1px solid red; color: white; > 100% width: 90vw; min-width: 24em; background-color: magenta; color: yellow; border: 1px solid orange; > >
.jump-start animation-timing-function: steps(5, jump-start); > .jump-end animation-timing-function: steps(5, jump-end); > .jump-none animation-timing-function: steps(5, jump-none); > .jump-both animation-timing-function: steps(5, jump-both); > .start animation-timing-function: steps(5, start); > .end animation-timing-function: steps(5, end); > .step-start animation-timing-function: step-start; > .step-end animation-timing-function: step-end; >
Specifications
Browser compatibility
BCD tables only load in the browser
See also
- Using CSS animations
- JavaScript AnimationEvent API
- cubic-bezier.com
- Other related animation properties: animation , animation-composition , animation-delay , animation-direction , animation-duration , animation-fill-mode , animation-iteration-count , animation-name , animation-play-state , animation-timeline
Found a content problem with this page?
This page was last modified on Jul 17, 2023 by MDN contributors.
Your blueprint for a better internet.
MDN
Support
Our communities
Developers
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license.