Briefly
transition
defines the function of dependency of the property value on time. In other words, this function determines the speed of the flow of the animation.
Example
In the example below, the color
property will change linearly (evenly) over 300 ms.
.box { transition-property: color; transition-duration: .3s; transition-timing-function: linear;}
.box { transition-property: color; transition-duration: .3s; transition-timing-function: linear; }
How to write
Keywords as values:
.selector { transition-timing-function: ease; /* Used by default */ transition-timing-function: ease-in; transition-timing-function: ease-out; transition-timing-function: ease-in-out; transition-timing-function: linear; transition-timing-function: step-start; transition-timing-function: step-end;}
.selector { transition-timing-function: ease; /* Used by default */ transition-timing-function: ease-in; transition-timing-function: ease-out; transition-timing-function: ease-in-out; transition-timing-function: linear; transition-timing-function: step-start; transition-timing-function: step-end; }
Function descriptions as values:
.selector { transition-timing-function: steps(4, jump-end); transition-timing-function: cubic-bezier(0.1, 0.7, 1.0, 0.1);}
.selector { transition-timing-function: steps(4, jump-end); transition-timing-function: cubic-bezier(0.1, 0.7, 1.0, 0.1); }
Additional parameters for the Steps function:
.selector { transition-timing-function: steps(4, jump-start); transition-timing-function: steps(10, jump-end); transition-timing-function: steps(20, jump-none); transition-timing-function: steps(5, jump-both); transition-timing-function: steps(6, start); transition-timing-function: steps(8, end);}
.selector { transition-timing-function: steps(4, jump-start); transition-timing-function: steps(10, jump-end); transition-timing-function: steps(20, jump-none); transition-timing-function: steps(5, jump-both); transition-timing-function: steps(6, start); transition-timing-function: steps(8, end); }
Specifying multiple functions:
.selector { transition-timing-function: ease, step-start, cubic-bezier(0.1, 0.7, 1.0, 0.1);}
.selector { transition-timing-function: ease, step-start, cubic-bezier(0.1, 0.7, 1.0, 0.1); }
How to understand
For example, we need to change some property from 0 to 100 over 1 second. During this second, the value of the property can change at different speeds. How exactly — is described by our function.
For instance, if the property changes evenly throughout the second, then it is a linear dependency, which is described by the keyword linear
and looks like this:

If the property changes quickly at first, and then slower, this dependency is described by the keyword ease
and looks like this:

The cubic-bezier
Function
In general, the graph of the function is described by the value cubic
. The parameters p1 and p3 must be numbers from 0 to 1.
Each keyword corresponds to its function graph with specific coefficients:
linear
—cubic
- bezier ( 0 . 0 , 0 . 0 , 1 . 0 , 1 . 0 ) ease
—cubic
- bezier ( 0 . 25 , 0 . 1 , 0 . 25 , 1 . 0 ) ease
—- in cubic
- bezier ( 0 . 42 , 0 , 1 . 0 , 1 . 0 ) ease
—- out cubic
- bezier ( 0 , 0 , 0 . 58 , 1 . 0 ) ease
—- in - out cubic
- bezier ( 0 . 42 , 0 , 0 . 58 , 1 . 0 )
The steps
Function
The property can be changed not smoothly, but in jumps. The steps
function describes how many steps the property change should happen in.
.box { transition-timing-function: steps(5, jump-start);}
.box { transition-timing-function: steps(5, jump-start); }
The first parameter indicates the number of steps over which the property will change. Each step will be displayed for an equal amount of time.
The second parameter defines the logic by which the interval will be divided into segments.
For example, if the first parameter is 5, then there will be a total of 5 steps. At each step, the display will pause, following one of the conditions depending on the second parameter. The second parameter can take the following values:
jump
, jump
, jump
, jump
, start
, end
- at 20%, 40%, 60%, 80%, and 100% —
jump
. At the moment the animation starts, the current value will jump immediately to 20% and pause there for $1/5$ of the time.- start - at 0%, 20%, 40%, 60%, and 80% —
jump
. The current value starts pausing immediately at 0%.- end - or will make 5 stops in the interval between 0% and 100% (16%, 33%, 50%, 66%, 84%) —
jump
- both - or will make 5 stops, including 0% and 100% (0%, 25%, 50%, 75%, 100%) —
jump
- none
Interestingly, Safari did not support these values until version 13.1 (Catalina) 🤷♂️
Starting from version 14 (Big Sur), everything is fine in Safari 🙂
Depending on the current browser in use, the example below may vary:
The keywords step
and step
are synonyms for the notation steps
and steps
. The change occurs in a jump in one step.
step
transitions to the final state immediately at the start of the animation and waits for the end of the animation.
step
waits for the end of the animation and then transitions to the final state.
Tips
💡 If the transition
property is not specified, the browser will use the ease
function and its corresponding description cubic
by default.
💡 By setting coefficients p2
and p4
less than 0 or greater than 1, you can achieve a "spring" effect, which in some cases can make the animation more interesting.
In practice
Advice 1
🛠 The most commonly used animation function is ease
. Mainly because developers are too lazy to write the function value, and the default in the browser is indeed ease
.
Advice 2
🛠 If you want to create a cool animation and understand how your Bézier curve should look, you can use a special site, for example https://cubic-bezier.com/.
.selector { transition-timing-function: cubic-bezier(1, .2, .52, .46);}
.selector { transition-timing-function: cubic-bezier(1, .2, .52, .46); }
Advice 3
🛠 If you are creating an animation that mimics the real world, it is very important to choose the animation timing function correctly. Because in the real world, nothing moves abruptly or linearly.