🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEcss

css Documentation

LOADING ENGINE...

Animation-timing-function

AI & DATA SCIENCE // animation-timing-function

The animation-timing-function property sets the acceleration curve an animation follows within each cycle, working identically to transition-timing-function but applied to a @keyframes animation instead.

Syntax

animation-timing-function: ease | linear | ease-in | ease-out | ease-in-out | steps(n) | cubic-bezier(...);

Deep Dive Course

This property accepts the same standard keyword values as transition-timing-function, ease, linear, ease-in, ease-out, and ease-in-out, but additionally supports the steps() function, which is unique to more complex, multi-keyframe animations and produces an animation that jumps directly between a fixed number of discrete positions, rather than interpolating smoothly, useful for effects like a sprite-sheet animation or a mechanical, ticking-clock-style motion. When more than two keyframes are defined, the specified timing function's easing curve applies independently to each individual segment between consecutive keyframes, not as a single easing curve stretched across the entire overall animation.

1Understanding Animation-timing-function

This property accepts the same standard keyword values as transition-timing-function, ease, linear, ease-in, ease-out, and ease-in-out, but additionally supports the steps() function, which is unique to more complex, multi-keyframe animations and produces an animation that jumps directly between a fixed number of discrete positions, rather than interpolating smoothly, useful for effects like a sprite-sheet animation or a mechanical, ticking-clock-style motion. When more than two keyframes are defined, the specified timing function's easing curve applies independently to each individual segment between consecutive keyframes, not as a single easing curve stretched across the entire overall animation.

💡

Use steps(n) instead of a smooth easing keyword specifically for effects that should visibly jump between a fixed number of discrete positions, like a sprite-sheet frame animation or a mechanical, ticking clock hand, rather than interpolating smoothly between them.

editor.html
@keyframes tick {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.clock-hand {
  animation: tick 12s steps(12) infinite;
}
localhost:3000

2Practical Example

Here is a real-world application of Animation-timing-function showing how it is used in production CSS code.

editor.html
@keyframes sprite {
  from { background-position: 0 0; }
  to { background-position: -800px 0; }
}

.character {
  animation: sprite 0.8s steps(8) infinite;
}
localhost:3000

3Best Practices

Follow these guidelines when working with Animation-timing-function:

1. Use steps(n) for sprite-sheet or frame-based animations, and other effects that should visibly jump between discrete positions rather than smoothly interpolate

2. Remember the specified timing function applies independently to each segment between consecutive keyframes in a multi-keyframe animation, not as one single curve stretched across the whole animation

3. Match the timing function's character to the animation's intended feel, a bouncy, playful effect might call for a custom cubic-bezier() curve rather than one of the standard, more neutral keyword presets

⚠️

Tip: Use steps(n) instead of a smooth easing keyword specifically for effects that should visibly jump between a fixed number of discrete positions, like a sprite-sheet frame animation or a mechanical, ticking clock hand, rather than interpolating smoothly between them.

editor.html
@keyframes tick {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.clock-hand {
  animation: tick 12s steps(12) infinite;
}
localhost:3000

Examples

Example 01Basic Usage
@keyframes tick {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.clock-hand {
  animation: tick 12s steps(12) infinite;
}
Example 02Advanced Example
@keyframes sprite {
  from { background-position: 0 0; }
  to { background-position: -800px 0; }
}

.character {
  animation: sprite 0.8s steps(8) infinite;
}

Best Practices

  • Use steps(n) for sprite-sheet or frame-based animations, and other effects that should visibly jump between discrete positions rather than smoothly interpolate
  • Remember the specified timing function applies independently to each segment between consecutive keyframes in a multi-keyframe animation, not as one single curve stretched across the whole animation
  • Match the timing function's character to the animation's intended feel, a bouncy, playful effect might call for a custom cubic-bezier() curve rather than one of the standard, more neutral keyword presets

Interview Question

Why does steps(n) produce a visibly different kind of motion, distinct jumps rather than smooth movement, compared to a standard easing keyword like ease or linear?

Hint: Think about how many actual distinct rendered positions the browser calculates and displays during the animation under each approach — a continuous, ever-changing value, or a fixed, limited set of specific stopping points.

Standard easing keywords like ease or linear are defined as smooth, continuous mathematical curves that produce a genuinely different, gradually-changing intermediate value at essentially every single rendered frame throughout the animation, which is exactly what the eye perceives as smooth, fluid motion, since the displayed value is constantly, continuously updating in tiny, gradual increments. steps(n), by contrast, explicitly divides the animation's timeline into exactly n discrete, fixed segments, and instead of smoothly interpolating a continuously-changing value, it holds the animated property at one single, fixed value for the entire duration of each individual step, only jumping abruptly to the next fixed value once that step's time period has fully elapsed, producing a sequence of only n distinct, discrete rendered positions across the whole animation, no matter how long the animation's overall duration actually is. This fundamental difference, continuously interpolating an ever-changing value versus holding a fixed value for each of a limited number of discrete steps before jumping, is exactly what produces steps()'s characteristic jumpy, stop-motion-like visual effect, deliberately distinct from the smooth, fluid motion the standard easing keywords are designed to produce instead.

Exercises

MediumPractice using Animation-timing-function in a real scenario.
View Solution
@keyframes tick {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.clock-hand {
  animation: tick 12s steps(12) infinite;
}

Frequently Asked Questions

Why does steps(n) produce a visibly different kind of motion, distinct jumps rather than smooth movement, compared to a standard easing keyword like ease or linear?

Standard easing keywords like ease or linear are defined as smooth, continuous mathematical curves that produce a genuinely different, gradually-changing intermediate value at essentially every single rendered frame throughout the animation, which is exactly what the eye perceives as smooth, fluid motion, since the displayed value is constantly, continuously updating in tiny, gradual increments. steps(n), by contrast, explicitly divides the animation's timeline into exactly n discrete, fixed segments, and instead of smoothly interpolating a continuously-changing value, it holds the animated property at one single, fixed value for the entire duration of each individual step, only jumping abruptly to the next fixed value once that step's time period has fully elapsed, producing a sequence of only n distinct, discrete rendered positions across the whole animation, no matter how long the animation's overall duration actually is. This fundamental difference, continuously interpolating an ever-changing value versus holding a fixed value for each of a limited number of discrete steps before jumping, is exactly what produces steps()'s characteristic jumpy, stop-motion-like visual effect, deliberately distinct from the smooth, fluid motion the standard easing keywords are designed to produce instead.

Related Functions

Transition-timing-functionAnimationKeyframes