The <easingfunction>
CSS data type denotes a mathematical function that describes the rate at which a numerical value changes.
This transition between two values may be applied in different situations. It may be used to describe how fast values change during animations. This lets you vary the animation's speed over the course of its duration. It may also be used to interpolate between two colors in a color gradient.
The easing functions in the cubicbezier subset of easing functions are often called "smooth" easing functions, because they can be used to smooth down the start and end of the interpolation. They correlate an input ratio to an output ratio, both expressed as <number>
s. For these values, 0.0
represents the initial state, and 1.0
represents the final state.
Depending on the specific function used, the calculated output can sometimes grow to be greater than 1.0
or smaller than 0.0
during the course of an animation. This causes the value to go farther than the final state, and then return. In animations, for some properties, such as left
or right
, this creates a kind of "bouncing" effect.
However, certain properties will restrict the output if it goes outside an allowable range. For example, a color component greater than 255
or smaller than 0
will be clipped to the closest allowed value (255
and 0
, respectively). Some cubicbezier()
curves exhibit this property.
Syntax
There are three types of easing function: linear, cubic Bézier curves, and staircase functions. The value of an <easingfunction>
type describes the easing function using one of those three types.
Easing functions
CSS supports three kinds of easing functions: linear, the subset of the cubic Bézier curves that are functions, and staircase functions. The most useful of these functions are given a keyword that allows them to be easily referenced.
The linear class of easing functions
linear
The interpolation is done at a constant rate from beginning to end. This keyword represents the easing function cubicbezier(0.0, 0.0, 1.0, 1.0)
.
The cubicbezier() class of easing functions
The cubicbezier()
functional notation defines a cubic Bézier curve. As these curves are continuous, they are often used to smooth down the start and end of the interpolation and are therefore sometimes called easing functions.
A cubic Bézier curve is defined by four points P_{0}, P_{1}, P_{2}, and P_{3}. P_{0} and P_{3} are the start and the end of the curve and, in CSS these points are fixed as the coordinates are ratios (the abscissa the ratio of time, the ordinate the ratio of the output range). P_{0} is (0, 0)
and represents the initial time or position and the initial state, P_{3} is (1, 1)
and represents the final time or position and the final state.
Not all cubic Bézier curves are suitable as easing functions as not all are mathematical functions; i.e., curves that for a given abscissa have zero or one value. With P_{0} and P_{3} fixed as defined by CSS, a cubic Bézier curve is a function, and is therefore valid, if and only if the abscissas of P_{1} and P_{2} are both in the [0, 1]
range.
Cubic Bézier curves with the P_{1} or P_{2} ordinate outside the [0, 1]
range may generate bouncing effects.
When you specify an invalid cubicbezier
curve, CSS ignores the whole property.
Syntax
cubicbezier(x1, y1, x2, y2)
where:
 x_{1}, y_{1}, x_{2}, y_{2}
 Are
<number>
values representing the abscissas, and ordinates of the P_{1} and P_{2} points defining the cubic Bézier curve. x_{1} and x_{2} must be in the range [0, 1] or the value is invalid.
Keywords for common cubicbezier easing functions
ease
The interpolation starts slowly, accelerates sharply, and then slows gradually towards the end. This keyword represents the easing function cubicbezier(0.25, 0.1, 0.25, 1.0)
. It is similar to easeinout
, though it accelerates more sharply at the beginning.
easein
The interpolation starts slowly, and then progressively speeds up until the end, at which point it stops abruptly. This keyword represents the easing function cubicbezier(0.42, 0.0, 1.0, 1.0)
.
easeinout
The interpolation starts slowly, speeds up, and then slows down towards the end. This keyword represents the easing function cubicbezier(0.42, 0.0, 0.58, 1.0)
. At the beginning, it behaves like the easein
function; at the end, it is like the easeout
function.
easeout
The interpolation starts abruptly, and then progressively slows down towards the end. This keyword represents the easing function cubicbezier(0.0, 0.0, 0.58, 1.0)
.
The steps() class of easing functions
The steps()
functional notation defines a step function dividing the domain of output values in equidistant steps.This subclass of step functions are sometimes also called staircase functions.
Syntax
steps(number_of_steps, direction)
where:
 number_of_steps
 Is a strictly positive
<integer>
, representing the amount of equidistant treads composing the stepping function.  direction
 Is a keyword indicating if it the function is left or rightcontinuous:

jumpstart
denotes a leftcontinuous function, so that the first step or jump happens when the interpolation begins;jumpend
denotes a rightcontinuous function, so that the last step or jump happens when the interpolation ends;jumpboth
denotes a right and left continuous function, includes pauses at both the 0% and 100% marks, effectively adding a step during the interpolation iteration;jumpnone
There is no jump on either end. Instead, holding at both the 0% mark and the 100% mark, each for 1/n of the durationstart
is the equivalent ofjumpstart
end
is the equivalent ofjumpend
end
is the default.
steps( n, <direction> )

steps(2, jumpstart)
steps(2, start)

steps(4, jumpend)
steps(4, end) 
steps(5, jumpnone)

steps(3, jumpboth)
stepstart
The interpolation jumps immediately to its final state, where it stays until the end. This keyword represents the easing function steps(1, jumpstart)
or steps(1, start)
.
stepend
The interpolation stays in its initial state until the end, at which point it jumps directly to its final state. This keyword represents the easing function steps(1, jumpend)
or steps(1, end)
.
Examples
Easing function comparison
This example creates an animation that can be started and stopped again using the provided button, and a select menu that can be used to switch its easing function between the available keywords, plus a couple of cubicbezier()
and steps()
options. The idea is to provide an easy comparison between different easing functions.
HTML
<div>
<div></div>
</div>
<ul>
<li>
<button class="animationbutton">Start animation</button>
</li>
<li>
<label for="easingselect">Choose an easing function:</label>
<select id="easingselect">
<option selected>linear</option>
<option>ease</option>
<option>easein</option>
<option>easeinout</option>
<option>easeout</option>
<option>cubicbezier(0.1, 0.6, 0.2, 0)</option>
<option>cubicbezier(0, 1.1, 0.8, 4)</option>
<option>steps(5, end)</option>
<option>steps(3, start)</option>
<option>steps(4)</option>
</select>
</li>
</ul>
CSS
body > div {
position: relative;
height: 100px;
}
div > div {
position: absolute;
width: 50px;
height: 50px;
backgroundcolor: blue;
backgroundimage: radialgradient(circle at 10px 10px, rgba(25,255,255,0.8),rgba(25,255,255,0.4));
borderradius: 50%;
top: 25px;
animation: 1.5s infinite alternate;
}
@keyframes moveright {
from {
left: 10%;
}
to {
left: 90%;
}
}
li {
display: flex;
alignitems: center;
justifycontent: center;
marginbottom: 20px;
}
JavaScript
const selectElem = document.querySelector('select');
const startBtn = document.querySelector('button');
const divElem = document.querySelector('div > div');
startBtn.addEventListener('click', () => {
if(startBtn.textContent === 'Start animation') {
divElem.style.animationName = 'moveright';
startBtn.textContent = 'Stop animation';
divElem.style.animationTimingFunction = selectElem.value;
} else {
divElem.style.animationName = 'unset';
startBtn.textContent = 'Start animation';
}
});
selectElem.addEventListener('change', () => {
divElem.style.animationTimingFunction = selectElem.value;
});
Result
cubicbezier() function examples
These cubic Bézier curves are valid for use in CSS:
/* The canonical Bézier curve with four <number> in the [0,1] range. */
cubicbezier(0.1, 0.7, 1.0, 0.1)
/* Using <integer> is valid as any <integer> is also a <number>. */
cubicbezier(0, 0, 1, 1)
/* Negative values for ordinates are valid, leading to bouncing effects.*/
cubicbezier(0.1, 0.6, 0.2, 0)
/* Values > 1.0 for ordinates are also valid. */
cubicbezier(0, 1.1, 0.8, 4)
These cubic Bézier curves definitions are invalid:
/* Though the animated output type may be a color,
Bézier curves work w/ numerical ratios.*/
cubicbezier(0.1, red, 1.0, green)
/* Abscissas must be in the [0, 1] range or
the curve is not a function of time. */
cubicbezier(2.45, 0.6, 4, 0.1)
/* The two points must be defined, there is no default value. */
cubicbezier(0.3, 2.1)
/* Abscissas must be in the [0, 1] range or
the curve is not a function of time. */
cubicbezier(1.9, 0.3, 0.2, 2.1)
steps() function examples
These easing functions are valid:
/* There is 5 treads, the last one happens
right before the end of the animation. */
steps(5, end)
/* A twostep staircase, the first one happening
at the start of the animation. */
steps(2, start)
/* The second parameter is optional. */
steps(2)
Note:
If the animation contains multiple stops, then the steps specified in the steps()
function will apply to each section. Therefore an animation with three segments and steps(2)
will contain 6 steps in total, 2 per segment.
These easing function are invalid:
/* The first parameter must be an <integer> and
cannot be a real value, even if it is equal to one. */
steps(2.0, jumpend)
/* The amount of steps must be nonnegative. */
steps(3, start)
/* There must be at least one step.*/
steps(0, jumpnone)
Specifications
Specification  Status  Comment 

CSS Easing Functions Level 1 The definition of '<easingfunction>' in that specification. 
Candidate Recommendation  Initial definition. 
Browser compatibility
BCD tables only load in the browser