A spring is the easing that makes an interface feel physical: it moves fast, passes its target by a hair and settles. For years that needed JavaScript on every frame. CSS can now do it in a transition, with no script running at all. This article shows how to turn a spring into a CSS easing, how many points you need, where the technique stops working, and what to do for people who have asked for less motion. The buttons on this site use exactly this.
Why a curve is not enough
A cubic-bezier() easing has two control points. It can speed up, slow down and even overshoot once. It cannot overshoot and then come back and settle with the shape a spring has, because that shape is not a single curve. It is a decaying wave.
The linear() easing function removes the limit. Instead of two control points you give it a list of values, and the browser draws straight lines between them. By default the values are spread evenly over the duration, and values above 1 or below 0 are allowed, which is what an overshoot needs.
/* Three points: start, halfway, end. */
transition: transform 300ms linear(0, 0.8, 1);
With enough points, straight lines are indistinguishable from a curve. So the job becomes: calculate where a spring is at each moment, and write those positions down.
Where a spring is at any moment
A spring pulling an object towards a target, with friction, has a known solution. For the kind that overshoots it looks like this:
/** Position of a damped spring from 0 to 1 over time (in seconds), starting at rest. */
function springAt(t, { stiffness, damping, mass = 1 }) {
const w0 = Math.sqrt(stiffness / mass); // natural frequency
const zeta = damping / (2 * Math.sqrt(stiffness * mass)); // damping ratio
if (zeta < 1) {
const wd = w0 * Math.sqrt(1 - zeta * zeta);
return 1 - Math.exp(-zeta * w0 * t) *
(Math.cos(wd * t) + ((zeta * w0) / wd) * Math.sin(wd * t));
}
return 1 - Math.exp(-w0 * t) * (1 + w0 * t); // no overshoot
}
The damping ratio decides the character. Below 1 the spring overshoots; the closer to 0, the longer it keeps bouncing. At 1 it arrives as fast as possible without passing the target. For interface elements a ratio around 0.8 is a good place to start: a visible settle, no wobble.
From positions to CSS
Sample the function at even steps and join the results:
function springToLinear(spring, durationMs, points = 25) {
const stops = Array.from({ length: points }, (_, i) => {
const t = (i / (points - 1)) * (durationMs / 1000);
return Number(springAt(t, spring).toFixed(3));
});
stops[points - 1] = 1; // an easing has to end exactly on its target
return `${durationMs}ms linear(${stops.join(", ")})`;
}
springToLinear({ stiffness: 400, damping: 32 }, 400);
That call returns:
400ms linear(0, 0.046, 0.155, 0.291, 0.431, 0.562, 0.676, 0.771, 0.846, 0.903,
0.945, 0.974, 0.993, 1.005, 1.012, 1.015, 1.015, 1.014, 1.012, 1.01, 1.008,
1.006, 1.004, 1.003, 1)
The spring passes its target after about 210 milliseconds, peaks one and a half percent above it and is back within a fraction of a percent at the end. Put the whole string in a custom property and use it wherever you would write a duration and an easing:
:root { --spring: 400ms linear(0, 0.046, 0.155, /* … */ 1.003, 1); }
.button { transition: gap var(--spring), background-color var(--spring); }

How many points
Twenty-five points over 400 milliseconds is one point every 16.7 milliseconds, which is one per frame on a 60 Hz screen. More points than frames cannot be seen. Fewer is often fine too: the curve is smooth, so ten or twelve points already look right for a spring this calm. A livelier spring, with several bounces, needs more.
The last value deserves a second look. A spring never mathematically arrives, so the sampled value at the end is something like 1.002. Set it to exactly 1, or the element finishes a hair off its target and jumps.
If you would rather not carry the maths around, the Motion library exports a spring() function that produces the same kind of string for use in a CSS transition.
Where it stops working
A real spring carries velocity. If you interrupt it halfway, it continues from where it is, at the speed it has. A CSS transition does not. Reverse a hover in the middle and the browser starts a new transition from the current value, with the same curve from the beginning, as if the element had been standing still.
For a hover on a button that is invisible. For anything you drag, throw or interrupt often, it is not, and that is still a job for JavaScript.
The other limit is duration. A spring's duration follows from its stiffness and damping. A transition's duration is something you choose. If you change one without the other, the curve gets cut off before it settles or sits idle at the end.
linear() is supported in the current versions of Chrome, Edge, Firefox and Safari. For older browsers, declare a plain transition first and the spring after it. A browser that does not understand linear() ignores the second line and keeps the first.
Less motion on request
Some people get dizzy or nauseous from interface motion, and operating systems let them say so. The Web Content Accessibility Guidelines address animation triggered by interaction in success criterion 2.3.3, and the advice there is to honour that setting. In CSS it is one media query:
@media (prefers-reduced-motion: reduce) {
.button { transition: none; }
}
The state still changes. The button still widens when you point at it. It just does so at once. That is the test for whether motion was decoration or a dependency: switch it off and check that nothing has become unreachable. How the rest of this site handles it is on the motion system page.
Sources
- MDN: linear() easing function, consulted 10 November 2026.
- Motion: spring, on generating a spring for a CSS transition.
- W3C: Understanding Success Criterion 2.3.3, Animation from Interactions.
- MDN: prefers-reduced-motion.
- The code in this article was run in Node.js, and the output shown is its actual output.
