Course contentsShow
← React
Lesson 1961 of 2,39645. AnimationsFree lesson

Timing Functions and Duration

Control animation feel with ease-in, ease-out, cubic-bezier, and duration values in transition declarations.

Timing Functions and Duration

You'll learn how to control the feel of your animations by adjusting how quickly they accelerate, decelerate, and how long they take.

The Speed Curve of Your Animation

When you add transition to a React component, you can specify how long it takes and how it progresses through time. Duration is straightforward—it's the total time. But timing functions define the acceleration curve: does the animation start slow and speed up? Start fast and slow down? Move at constant speed?

Think of timing functions like different elevator rides. linear is a freight elevator moving at constant speed—functional but mechanical. ease-in starts slow like a gentle departure, building speed. ease-out arrives smoothly, decelerating at the end. ease-in-out combines both for a natural, human feel.

The Syntax

transition: opacity 300ms ease-in-out;

Here, 300ms is the duration (how long), and ease-in-out is the timing function (how it feels).

Common Timing Functions

  • linear: Constant speed, robotic feel
  • ease: Default, slight ease-in and ease-out
  • ease-in: Slow start, fast finish
  • ease-out: Fast start, slow finish (great for entrances)
  • ease-in-out: Smooth both ends (feels most natural)
  • cubic-bezier(x1, y1, x2, y2): Custom curve for precise control
<div
  className={isOpen ? 'open' : 'closed'}
  style={{
    transition: 'transform 500ms cubic-bezier(0.68, -0.55, 0.27, 1.55)',
    transform: isOpen ? 'scale(1)' : 'scale(0)'
  }}
/>

Key Takeaway: Duration controls how long your animation takes, while timing functions control how it feels—use ease-out for smooth entrances, ease-in-out for state changes, and cubic-bezier() for custom personality.