001
How to read an easing curve
An easing curve never changes how long a motion takes, only where its time is spent. Four live pens make that visible, and show why this site's buttons settle the way they do.
An easing curve never changes how long an animation lasts. A 1.2-second move takes 1.2 seconds under every curve. What the curve decides is where those seconds go: how much of the distance is covered early, and how much time is left for the end.
That is easier to see than to read. The pens below are live: the code is yours to change, and it runs again as you type.
Same clock, three journeys
Three dots, one duration, one distance. Only transition-timing-function differs.
<div class="lane"><span class="dot linear"></span><code>linear</code></div> <div class="lane"><span class="dot in-out"></span><code>ease-in-out</code></div> <div class="lane"><span class="dot out"></span><code>0.16, 1, 0.3, 1</code></div> <button type="button">Play</button>
The linear dot is the plain one: half the time, half the way. Ease-in-out holds back, then hurries through the middle. The last dot uses cubic-bezier(0.16, 1, 0.3, 1), the curve this site's buttons use. It is nearly there before the others have properly started.
Try cubic-bezier(0.7, 0, 0.84, 0) in the .out rule. It is the same shape turned around: it waits, then leaves in a rush.
The curve is a clock
Every easing curve is a graph in a square. Time runs along the bottom, from the first frame to the last. Progress runs up the side, from where the element starts to where it lands. The curve always leaves the bottom-left corner and reaches the top-right; only its shape in between changes.
Reading it takes one move. Pick a moment on the bottom edge, go straight up to the curve, and look left. That height is how far along the motion is at that moment. A straight diagonal is linear. A curve that climbs steeply and then flattens has done most of its moving early.
The four numbers in cubic-bezier(x1, y1, x2, y2) place two handles, the same ones a pen tool gives you in a drawing app. The first, (x1, y1), pulls on the curve as it leaves the start. The second, (x2, y2), pulls on it as it comes into the end. The curve bends toward each handle without passing through it.
In cubic-bezier(0.16, 1, 0.3, 1), both handles sit on the top edge, at full progress. The first is pulled almost straight up from the start, so the curve shoots upward and then runs nearly flat into the end.
<svg viewBox="0 0 240 240" role="img" aria-label="The easing curve with its two handles"> <rect class="frame" x="20" y="20" width="200" height="200" /> <path class="handle" id="handle-1" /> <path class="handle" id="handle-2" /> <circle class="knob" id="knob-1" r="4" /> <circle class="knob" id="knob-2" r="4" /> <path class="curve" id="curve" /> <path class="reading" id="reading" /> <circle class="mark" id="mark" r="4" /> <text x="220" y="236" text-anchor="end">time →</text> <text x="-20" y="12" text-anchor="end" transform="rotate(-90)">progress →</text> </svg> <div class="controls"> <input type="range" min="0" max="1" step="0.01" value="0.25" aria-label="Time" /> <output></output> </div>
Move the slider to walk through time: the faint line goes up to the curve and across to the progress it has reached. Change the four numbers on the first line of the JS to draw another curve. Try 0.42, 0, 0.58, 1, which is ease-in-out.
Reading by eye is close enough to see the shape. For exact numbers, ask the browser. With the Web Animations API, an animation can be paused and moved to any moment, and getComputedTiming().progress reports the eased progress there. This pen asks at every quarter of the duration and draws the answers.
<div id="chart"></div>
The console holds the same numbers. At a quarter of the time, ease-in-out has covered 13% of the distance; the site's curve has covered 83%. By the half it stands at 97%. It reaches nine tenths of the way in the first third of the duration, and spends the other two thirds on the last tenth.
Where 83% comes from
The browser works these numbers out from the four values in cubic-bezier(), and the sum is short enough to follow by hand. It takes four steps.
Time becomes a fraction. Divide the time that has passed by the duration.
t = elapsed / duration; // 300ms / 1200ms = 0.25t runs from 0 on the first frame to 1 on the last, whatever the duration. That is why one curve can serve a 200ms hover and a two-second page change.
A point on the curve is a blend. A Bézier curve is drawn the way a pen draws it. A second number, s, says how far along the stroke the pen is, from 0 to 1. At each s, the pen sits at a weighted mix of the four points: the start, the first handle, the second handle, and the end.
start = (1 - s) ** 3
first = 3 * (1 - s) ** 2 * s
second = 3 * (1 - s) * s ** 2
end = s ** 3The four weights always add up to 1. Early in the stroke, the start and the first handle carry most of it; late in the stroke, the second handle and the end take over. That shift is the pull you see the handles exert. The start sits at 0, so its share always drops out, and the end sits at 1, so its share is end itself.
x = first * x1 + second * x2 + end;
y = first * y1 + second * y2 + end;Halfway along the stroke, at s = 0.5, the weights are ⅛, ⅜, ⅜ and ⅛. On this site's curve:
x = 0.375 * 0.16 + 0.375 * 0.3 + 0.125; // 0.2975
y = 0.375 * 1 + 0.375 * 1 + 0.125; // 0.875Half the stroke is drawn, under a third of the time has passed, and the dot is seven eighths of the way there. Both handles sit at full height, so they lift y far faster than x moves.
A search finds the moment. The clock gives x, and the sum needs s. There is no neat way to run it backwards, so the code guesses, checks, and halves. For t = 0.25:
s = 0.5givesx = 0.298. Too late.s = 0.25givesx = 0.125. Too early.s = 0.375givesx = 0.202. Too early.s = 0.4375givesx = 0.247. Just short.
Each guess halves the range the answer can be in. Thirty guesses narrow it to about a billionth and land on s = 0.441. Its y is 0.826: the 83% the browser reported. That is all of progressAt in the second pen. along is the blend, and the loop is the search. Browser engines reach the same answer with a search that needs fewer guesses.
Progress becomes a value. Progress is a fraction too, so it scales whatever is moving.
value = from + progress * (to - from); // 0 + 0.826 * 300px = 248pxNothing in these sums holds y between 0 and 1. A handle above the top edge pushes progress past 1, and the value past to. The next pen lets you try it.
Bend it yourself
The sliders are the four numbers. Shape a curve, then press Play. The dot runs on it, and the mark rides the graph beside it, read from the same getComputedTiming() once a frame.
<svg viewBox="-8 -58 116 216" role="img" aria-label="Your curve and its two handles"> <rect class="frame" x="0" y="0" width="100" height="100" /> <path class="handle" id="handle-1" /> <path class="handle" id="handle-2" /> <circle class="knob" id="knob-1" r="3" /> <circle class="knob" id="knob-2" r="3" /> <path class="curve" id="curve" /> <path class="reading" id="reading" /> <circle class="mark" id="mark" cx="0" cy="100" r="3" /> </svg> <div class="controls"> <label>x1 <input type="range" min="0" max="1" step="0.01" value="0.16" /><output></output></label> <label>y1 <input type="range" min="-0.5" max="1.5" step="0.01" value="1" /><output></output></label> <label>x2 <input type="range" min="0" max="1" step="0.01" value="0.3" /><output></output></label> <label>y2 <input type="range" min="-0.5" max="1.5" step="0.01" value="1" /><output></output></label> <code></code> <button type="button">Play</button> </div> <div class="lane"><span class="dot"></span></div>
The x sliders stop at the edges of the square; the y sliders do not. Time only runs forward, so a handle cannot sit before the start or after the end. Progress is free to overshoot. Raise y1 to 1.5 and the dot passes its mark, then settles back onto it. Drop it below 0 and the dot draws back before it leaves.
Spending the time
That last stretch is the point. A motion that is almost finished reads as an answer: the button has already responded, and the long settle is the part the eye rests on. So the curve suits things that arrive.
- Arriving: ease-out. The change shows at once, and the time goes to settling.
- Leaving: ease-in. Slow to start, quickly gone; the eye has already moved on.
- Crossing: ease-in-out. Something that starts and ends on screen gets a gentle departure and a gentle arrival.
No curve is faster than another. Each is a choice about where the reader's attention goes, and the duration is only the budget for it.