liveBook · Manning

Timing function

As explained in CSS in Depth, Second Edition

A CSS timing function curve represents how the rate of change progresses over the duration of a transition or animation.

A transition moves a CSS property from one value to another. Its timing function controls how quickly the intermediate values change during that movement: at a steady rate, accelerating, or decelerating. It does not set the duration or the delay; those are separate transition settings. section 15.1 section 15.2

Start with a keyword that suits the interaction:

  • `linear` changes at a constant rate. section 15.2
  • `ease-in` starts slowly and accelerates; accelerating motion can help attract attention. section 15.2 section 15.6
  • `ease-out` starts rapidly and slows toward the end; decelerating motion can signal that an action has taken effect. section 15.2 section 15.6

Compare the motion in a browser

Position a box at `left: 0`, move it to `left: 400px` when its container is hovered, and give it `transition: all 1s linear`. Then replace `linear` with `ease-in` and `ease-out`. The box reaches the same destination in the same duration, but its movement feels different. This demonstrates timing clearly; for production motion, consider a transform instead of transitioning `left` for performance reasons. section 15.2 section 16.5

Figure 15.4 The Bézier curves of timing functions illustrate how the value changes over time.
figure

The curves show time progressing from left to right and the property value progressing toward its destination. A straight line is steady; curved lines change the rate. section 15.2.1

For more control, use `cubic-bezier()` instead of a keyword. Its four values define a custom curve. In browser DevTools, inspect an element, open the timing-function curve editor, and drag its control handles to explore shapes; the resulting `cubic-bezier()` value can be used in CSS. A curve can even make a translated label briefly overshoot its final position before settling back. section 15.2.1 section 16.2.2

A timing function can be specified for each transitioned property: `transition: border-radius 0.3s linear, background-color 0.6s ease;`. Keyframe animations also accept keyword or Bézier timing functions through `animation-timing-function`. When adding motion, account for reduced-motion preferences. section 15.1 section 17.1

How CSS in Depth, Second Edition covers it

How deep it goes
Explains keyword behaviors and Bézier curves, then demonstrates browser-based curve editing and a custom overshoot.
Examples
Compares a hovered moving box under three keywords and uses a translating navigation label to demonstrate bounce.
What it assumes
Assumes basic CSS selectors and property changes, while introducing timing behavior through a simple hover transition.
What you can do after
Apply it via CSS keywords or `cubic-bezier()` and adjust a custom curve with browser DevTools.
How it connects
Connects transition duration, transition shorthand, cubic Bézier curves, transforms, and keyframe animations.

Also explained in

Compare how 2 books explain timing function →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of CSS in Depth, Second Edition. The section links point to the parts of the book it draws on.