Spring animations in plain CSS with linear()

A spring feels right because it has no fixed curve: it pulls toward the target, overshoots a little and settles. CSS easings used to be cubic-bezier curves, which cannot overshoot and come back more than once. The linear() easing function changes that. It takes a list of points, and the browser draws straight lines between them, so a spring sampled into enough points plays as an ordinary CSS transition.

Try it with the spring generator: https://motionmart.store/tools/spring

1. Describe the spring

Three numbers define it. Stiffness is how hard the spring pulls toward the target, so higher is faster. Damping is friction: lower lets it overshoot and wobble, higher settles it without a bounce. Mass is how heavy the moving thing is, so more mass is slower and swings further.

The damping ratio, damping divided by 2 × √(stiffness × mass), tells you the character in one number. Below 1 the spring overshoots, at 1 it settles as fast as it can without overshooting, and above 1 it creeps in slowly.

2. Find how long it takes to settle

CSS needs a duration, and a spring has none, so measure one. Step the spring forward in small time steps and note the last moment it is further than a small tolerance from the target. The spring generator steps at 240 times a second for up to 8 seconds and uses 0.1% as the tolerance. That moment becomes the transition duration.

3. Sample the curve, then keep only the points it needs

Sample the position at evenly spaced moments across that duration. The generator takes 161 samples, so a fast wobble is not missed. Most of those points sit on nearly straight stretches, so thin them: keep a point only where leaving it out would bend the line by more than a small error. The generator uses the Ramer–Douglas–Peucker method with a tolerance of 0.0025, which keeps the overshoot and the settle and drops the rest.

Write each kept point as its value followed by where it falls in time as a percentage. The first point is 0 and the last is 1, so the easing ends exactly on the target.

:root {
  --spring: linear(0, …, 1); /* paste the generated list here */
  --spring-duration: 520ms;  /* the settle time from step 2 */
}
.panel {
  transition: transform var(--spring-duration) var(--spring);
}

4. Choose values for the job

When a JavaScript spring is still better

A linear() spring is a recording. It cannot be caught mid-flight and redirected the way a running spring can, so anything the user drags, flings or interrupts (sheets, swipe actions, sliders) should keep a JavaScript spring, such as Motion or a small physics loop. Use the CSS version for state changes that play to the end: menus opening, toggles, toasts, hover and press feedback.

Questions

Can CSS do spring animations?

Yes, with the linear() easing function. A spring sampled into linear() points plays as a normal CSS transition or animation, with no JavaScript, in current versions of Chrome, Edge, Firefox and Safari.

How do I pick the duration of a CSS spring?

Measure how long the spring takes to stay within a small tolerance of its target and use that time. The Motionmart spring generator uses 0.1% and shows the result as “Settles in”.

Is the spring generator free?

Yes. It runs in the browser with no sign-up, and copies the spring as a CSS linear() easing, a Motion transition or plain JavaScript.

Browse by use case