CSS animation-timing-function

The animation-timing-function property in CSS is used to specify the speed curve of the animation. It allows you to control how the animation progresses over time.

There are several predefined timing functions available in CSS:

Let's see an example of how to use the animation-timing-function property:


.element {
    width: 100px;
    height: 100px;
    background-color: red;
    animation: example 2s infinite;
    animation-timing-function: ease-in-out;
}

@keyframes example {
    0% { transform: scale(1); }
    50% { transform: scale(1.5); }
    100% { transform: scale(1); }
}
Result:

In this example, we have a div element that will scale up and down repeatedly using an animation with a duration of 2 seconds. The timing function applied is ease-in-out, which causes the animation to gradually accelerate and then decelerate smoothly. You can experiment with different timing functions to see how they affect the animation.