animation-timing-function
Sets the pacing curve of the animation between keyframes.
- Initial value
ease- Inherited
- No
- Animatable
- no
- Applies to
- all elements and the ::before and ::after pseudo-elements
- JavaScript
element.style.animationTimingFunction = "ease-in-out"
Example
#.typing {
width: 22ch;
white-space: nowrap;
overflow: hidden;
border-right: 2px solid;
animation: type 2.5s steps(22) infinite alternate;
}
@keyframes type {
from { width: 0; }
}<style>@keyframes type-it { from { width: 0; } }</style>
<p style="margin: 0; width: 22ch; white-space: nowrap; overflow: hidden; border-right: 2px solid #a78bfa; font-family: monospace; font-size: 16px; animation: type-it 2.5s steps(22) infinite alternate;">console.log("Hello!")</p>Definition and usage
#The animation-timing-function property defines how the pace of the animation changes. It works the same way as in transitions: linear, ease, ease-in, ease-out, ease-in-out, and the cubic-bezier(), linear(), and steps() functions.
An important detail: the timing function applies to each segment between keyframes separately, not to the whole animation. With keyframes at 0%, 50%, and 100%, the ease curve is applied twice.
You can also set the timing function inside a keyframe, which changes the pace only until the next keyframe.
Syntax
#animation-timing-function: ease | linear | ease-in | ease-out | ease-in-out | steps(…) | cubic-bezier(…) | linear(…);Values
#- A constant pace throughout the movement.
- A gentle start and a gentle stop.
- Five discrete steps, like a frame-by-frame animation.
cubic-bezier(.68,-0.55,.27,1.55)
spring
Pulling back before the movement and overshooting at the end.
Values in practice
#linear
.demo { animation-timing-function: linear; }ease-in-out
.demo { animation-timing-function: ease-in-out; }steps(5)
.demo { animation-timing-function: steps(5); }cubic-bezier(.68,-0.55,.27,1.55)
.demo { animation-timing-function: cubic-bezier(0.68, -0.55, 0.27, 1.55); }Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- A typewriter effect combines
steps()with the number of characters and a monospace font. - Remember that the function applies to each segment between keyframes separately.
Related entries
#Practise it in lessons
#Spotted a mistake or missing an example? Write to us.