CSS propertyAnimations

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"
On this page

Example

#
CSS
.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; }
}
Preview

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

#
Syntax
animation-timing-function: ease | linear | ease-in | ease-out | ease-in-out | steps(…) | cubic-bezier(…) | linear(…);

Values

#

Values in practice

#

linear

A constant pace throughout the movement.
.demo { animation-timing-function: linear; }

ease-in-out

A gentle start and a gentle stop.
.demo { animation-timing-function: ease-in-out; }

steps(5)

Five discrete steps, like a frame-by-frame animation.
.demo { animation-timing-function: steps(5); }

cubic-bezier(.68,-0.55,.27,1.55)

Pulling back before the movement and overshooting at the end.
.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.