Cubic-Bezier Timing Curves (CSS and Design Tools)
A cubic-bezier timing curve is an easing function you shape by dragging two handles: a Bézier curve from to with time across and progress up. The curve is traced by its own parameter , which is not time, so finding the progress at a given time means first solving , which computers do in a few Newton steps.
What the symbols mean
- Curve parameter
Runs from 0 to 1 along the curve. It is not time.
- First handle's time
The x coordinate of P₁; CSS requires 0 ≤ x₁ ≤ 1.
- Second handle's time
The x coordinate of P₂; CSS requires 0 ≤ x₂ ≤ 1.
What the symbols mean
- First handle's height
Any number: above 1 or below 0 makes the motion overshoot or pull back.
- Second handle's height
Any number, like y₁.
What the symbols mean
- Time
The fraction of the duration that has passed: the x you want to reach.
Explanation
A cubic-bezier timing curve is an easing function you design by placing two handles. It's what CSS means by cubic-bezier(x1, y1, x2, y2), and what the curve editor in most design and animation tools draws: a Bézier curve from to whose two middle control points and are the handles you drag. Across is time and up is progress, like every easing graph so far. The one twist is that a Bézier curve is drawn by a third number, a parameter that runs from to along the curve, and is not time. The point at parameter is : is a time and is the progress at that time. So to ask "how far along are we at time ?" you first find the with , then read off . That's the whole lesson: two cubics and one equation to solve.
The two cubics. A cubic Bézier with control points is
(Bernstein Polynomials and Tangents shows where those weights come from). With the first term vanishes, and with the last is just in each coordinate. Split into coordinates, that's the pair and in the formulas: the same weights, once with the handles' 's and once with their 's.
Why CSS insists . The spec rejects a cubic-bezier with either outside , and here's what that buys. Differentiate:
The first and last weights, and , are at least . The middle one can be negative (when ), but never by enough to win: dividing by and writing , the bracket is , which is at least as long as . Expanding, that's , and both terms are when . So never decreases: time never runs backward along the curve, and every time matches exactly one point. The 's have no such limit. A handle above or below makes the motion overshoot or pull back, the cubic-bezier way to get a back ease; cubic-bezier(0.34, 1.56, 0.64, 1) is a popular overshoot, peaking near .
Finding the progress at time . Solve for , then compute . There is a cubic formula, but browsers don't use it. Newton's method, which repeatedly follows the tangent line to where it hits the target, converges in a handful of steps because is smooth and increasing:
Each step follows the tangent line at to where it reaches height , and near the answer each step roughly squares the error. If is nearly (a flat stretch, which happens when a handle has near or ), a Newton step can shoot off, so browser engines typically fall back to bisection: since is increasing, test the middle of an interval known to hold the answer and keep the half where crosses . Each bisection step only halves the error, but it can't fail.
function cubicBezier(x1: number, y1: number, x2: number, y2: number) {
const bez = (s: number, p1: number, p2: number) => 3 * (1 - s) ** 2 * s * p1 + 3 * (1 - s) * s * s * p2 + s ** 3;
const dx = (s: number) => 3 * (1 - s) ** 2 * x1 + 6 * (1 - s) * s * (x2 - x1) + 3 * s * s * (1 - x2);
return (t: number) => {
let s = t;
for (let i = 0; i < 8; i++) {
const slope = dx(s);
if (Math.abs(slope) < 1e-6) break; // a real engine switches to bisection here
s = Math.min(1, Math.max(0, s - (bez(s, x1, x2) - t) / slope));
}
return bez(s, y1, y2);
};
}
Reading the handles. The tangent at each end of a Bézier curve points at its handle, so the speed at the start is the slope from to , , and the speed at the end is the slope from to , . A handle lying flat (, or ) means the motion starts, or ends, at rest. If a handle sits right on its endpoint, as in ease-out where , that fraction is , and the tangent points at the other handle instead: ease-out starts at slope .
The CSS keywords are all cubic-bezier curves:
| keyword | cubic-bezier | character |
|---|---|---|
ease (the default) | a brisk start, a long gentle finish | |
ease-in | starts at rest | |
ease-out | ends at rest | |
ease-in-out | rest at both ends, symmetric | |
linear | constant speed |
ease is what a CSS transition uses when you don't say. It starts at times the average speed, ends at rest, and is already about done at half time. For linear, and come out identical, so exactly.
A special case: , . Then
Time is the parameter, there's nothing to solve, and the progress is just the polynomial . With and it's : smoothstep is cubic-bezier(1/3, 0, 2/3, 1).
A common mistake. It's tempting to skip the solving and plug the time straight in as . For ease at half time, , but is only , so is the progress at time , not at . The right answer is about , a big difference on screen. Plugging in for works only in the special case , .
There are animations further down: ease playing in real time with de Casteljau's construction riding along, the wrong shortcut racing the right answer, Newton's method closing in on , and a handle you can move to see overshoot appear.
See it
Worked examples
For the CSS keyword ease, cubic-bezier(0.25, 0.1, 0.25, 1), find the point on the curve at parameter . What time and what progress does it stand for?
- 1
Write the time coordinate with and : .
Use Newton's method to find the progress of ease, cubic-bezier(0.25, 0.1, 0.25, 1), at half time, .
- 1
We need the with . For
ease, ; multiply out to get .
Practice
Type your answer and check it. Solve them all to complete the lesson.
The CSS keyword ease-out is cubic-bezier(0, 0, 0.58, 1). Find the point on its curve at parameter .
A transition uses cubic-bezier(1/3, 0.5, 2/3, 1). What is its progress at time ?
A drawer opens px in s with the timing curve cubic-bezier(0.3, 0.6, 0.7, 1). How fast is it moving, in px/s, at the instant it starts?
Which of these is not a valid CSS timing function?
For ease-in-out, cubic-bezier(0.42, 0, 0.58, 1), the time coordinate is . Take one Newton step for , starting from . What is , to 4 decimal places?
A button's background fades from opacity to opacity over ms with the timing curve cubic-bezier(1/3, 0, 2/3, 1). What is the opacity ms after the fade starts?
A dropdown menu grows from height to px over ms with the CSS default ease, cubic-bezier(0.25, 0.1, 0.25, 1), whose curve is and . How tall is the menu ms after it starts, to the nearest px?
The hardest one here. Get it, and you've got this lesson.
A designer wants a timing curve cubic-bezier(1/3, y1, 2/3, y2) that starts from rest and is done at half time. Find , and the largest progress the curve ever reaches. Enter , then the largest progress.
Where it's used
Every CSS transition and animation on the web runs through this math: the browser solves for each animated property on every frame, usually in a few Newton steps with a bisection fallback. Design tools hand developers four numbers instead of a curve, and the same four numbers drive animation libraries, mobile toolkits and game UI systems, so a timing curve designed once behaves the same everywhere. Motion designers shape the handles by eye (a long, flat second handle for a soft landing, a handle above 1 for a little overshoot) and the formulas let you predict the result: how fast an element starts, when it's half done, and whether it will poke past its target.