CSS animation-timing-function

The animation-timing-function property in CSS specifies how the animation progresses over time. It defines the speed curve of the animation, determining whether the animation starts slowly, speeds up, or has a consistent speed throughout its duration.


Syntax of animation-timing-function

</>
Copy
animation-timing-function: linear | ease | ease-in | ease-out | ease-in-out | step-start | step-end | steps(int, start | end) | cubic-bezier(n,n,n,n) | initial | inherit;

Values

ValueDescription
linearThe animation progresses at a constant speed.
easeThe animation starts slow, accelerates, and then slows down towards the end. This is the default value.
ease-inThe animation starts slow and accelerates towards the end.
ease-outThe animation starts fast and slows down towards the end.
ease-in-outThe animation starts slow, accelerates, and then slows down.
step-startThe animation jumps immediately to the first step.
step-endThe animation jumps immediately to the final step.
steps(int, start | end)Defines an animation with a specific number of steps. start begins each step at the start of the interval, and end ends each step at the end of the interval.
cubic-bezier(n,n,n,n)Defines a custom speed curve using cubic-bezier function. Each n is a value between 0 and 1.
initialSets the property to its default value (ease).
inheritInherits the value from the parent element.

Default Value

ease


Examples for animation-timing-function

Using the CSS animation-timing-function Property

The following examples demonstrate how the animation-timing-function property can be used to create various animation speed curves.

</>
Copy
/* Linear animation */
.element {
  animation-timing-function: linear;
}

/* Ease animation */
.element {
  animation-timing-function: ease;
}

/* Ease-in animation */
.element {
  animation-timing-function: ease-in;
}

/* Ease-out animation */
.element {
  animation-timing-function: ease-out;
}

/* Custom cubic-bezier curve */
.element {
  animation-timing-function: cubic-bezier(0.25, 0.1, 0.25, 1);
}

Example 1: Applying animation-timing-function

The following example demonstrates how to use different timing functions for animations that move elements horizontally.

index.html

</>
Copy
<!DOCTYPE html>
<html lang="en">
<head>
<style>
  @keyframes move {
    from {
      transform: translateX(0);
    }
    to {
      transform: translateX(200px);
    }
  }

  .linear {
    animation: move 3s linear infinite;
    background-color: lightgreen;
  }

  .ease {
    animation: move 3s ease infinite;
    background-color: lightblue;
  }

  .ease-in {
    animation: move 3s ease-in infinite;
    background-color: lightcoral;
  }

  .cubic-bezier {
    animation: move 3s cubic-bezier(0.25, 0.1, 0.25, 1) infinite;
    background-color: lightyellow;
  }
  
  div {
    width: 200px;
    height: 100px;
    line-height: 100px;
    text-align: center;
    margin: 10px;
    padding: 10px;
    border: 2px solid;
  }
</style>
</head>
<body>

<h1>CSS animation-timing-function Example</h1>

<div class="linear">Linear</div>
<div class="ease">Ease</div>
<div class="ease-in">Ease-in</div>
<div class="cubic-bezier">Cubic Bezier</div>

</body>
</html>

Linear (.linear)

  1. The animation-timing-function is set to linear.
  2. The animation progresses at a constant speed throughout its duration.
  3. The box moves from translateX(0) to translateX(200px) at a steady pace without acceleration or deceleration.
  4. The result is a light green box that slides smoothly to the right at a uniform speed.

Ease (.ease)

  1. The animation-timing-function is set to ease.
  2. The animation starts slowly, accelerates in the middle, and slows down toward the end.
  3. This creates a natural, smooth motion that mimics real-world acceleration and deceleration.
  4. The result is a light blue box that gradually gains and loses speed as it slides to the right.

Ease-in (.ease-in)

  1. The animation-timing-function is set to ease-in.
  2. The animation starts slowly and accelerates toward the end.
  3. The initial part of the animation is gradual, and it speeds up as it approaches translateX(200px).
  4. The result is a light coral box that begins moving slowly and then quickly slides to the right.

Cubic Bezier (.cubic-bezier)

  1. The animation-timing-function is set to cubic-bezier(0.25, 0.1, 0.25, 1).
  2. The cubic Bezier function creates a custom timing curve that defines the animation’s speed changes.
  3. In this case, the timing curve mimics the ease behavior, with a smooth start, acceleration in the middle, and a slow finish.
  4. The result is a light yellow box that moves with a custom acceleration and deceleration effect based on the Bezier curve.

Browser Support

The animation-timing-function property is supported in most modern browsers. Below is a compatibility table:

BrowserVersion
Chrome43
Edge10
Firefox16
Safari9
Opera30