The value of an <easing-function>
type describes the easing function using one of the three types that CSS supports: 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 cubic-bezier(0.0, 0.0, 1.0, 1.0)
.
The cubic-bezier() class of easing functions
The cubic-bezier()
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 P0, P1, P2, and P3. P0 and P3 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). P0 is (0, 0)
and represents the initial time or position and the initial state, P3 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 P0 and P3 fixed as defined by CSS, a cubic Bézier curve is a function, and is therefore valid, if and only if the abscissas of P1 and P2 are both in the [0, 1]
range.
Cubic Bézier curves with the P1 or P2 ordinate outside the [0, 1]
range may generate bouncing effects.
When you specify an invalid cubic-bezier
curve, CSS ignores the whole property.
Syntax
cubic-bezier(x1, y1, x2, y2)
where:
-
x1, y1, x2, y2
-
Are <number>
values representing the abscissas, and ordinates of the P1 and P2 points defining the cubic Bézier curve. x1 and x2 must be in the range [0, 1] or the value is invalid.
Keywords for common cubic-bezier easing functions
ease
The interpolation starts slowly, accelerates sharply, and then slows gradually towards the end. This keyword represents the easing function cubic-bezier(0.25, 0.1, 0.25, 1.0)
. It is similar to ease-in-out
, though it accelerates more sharply at the beginning.
ease-in
The interpolation starts slowly, and then progressively speeds up until the end, at which point it stops abruptly. This keyword represents the easing function cubic-bezier(0.42, 0.0, 1.0, 1.0)
.
ease-in-out
The interpolation starts slowly, speeds up, and then slows down towards the end. This keyword represents the easing function cubic-bezier(0.42, 0.0, 0.58, 1.0)
. At the beginning, it behaves like the ease-in
function; at the end, it is like the ease-out
function.
ease-out
The interpolation starts abruptly, and then progressively slows down towards the end. This keyword represents the easing function cubic-bezier(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 right-continuous:
-
jump-start
denotes a left-continuous function, so that the first step or jump happens when the interpolation begins;
-
jump-end
denotes a right-continuous function, so that the last step or jump happens when the interpolation ends;
-
jump-both
denotes a right and left continuous function, includes pauses at both the 0% and 100% marks, effectively adding a step during the interpolation iteration;
-
jump-none
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
-
start
is the equivalent of jump-start
-
end
is the equivalent of jump-end
end
is the default.
steps( n, <direction> )
-
steps(2, jump-start)
steps(2, start)
-
steps(4, jump-end) steps(4, end)
-
steps(5, jump-none)
-
steps(3, jump-both)
step-start
The interpolation jumps immediately to its final state, where it stays until the end. This keyword represents the easing function steps(1, jump-start)
or steps(1, start)
.
step-end
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, jump-end)
or steps(1, end)
.