Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

animation-timing-function: shape progress between keyframes

Change how values interpolate without changing the animation’s duration or starting a new animation.

Version: CSS Modules

Syntax

animation-timing-function: <easing-function>#;

animation-timing-function maps progress between keyframes to interpolation progress. The default ease is not linear: linear keeps a constant interpolation rate, while ease, cubic-bezier() and steps() reshape it. linear() can describe a piecewise linear curve. These functions do not select the animated property, create keyframes or change animation-duration. A comma-separated list matches the animation-name list; direction and iteration settings remain separate.

An easing declared inside a keyframe controls the interval from that keyframe to the next one for the relevant animated property. It can override the element’s timing function on that interval. A declaration on the final 100% keyframe has no following interval to control. In a cubic-bezier(), the X control coordinates must lie between 0 and 1; the Y coordinates can go outside that interval. A steps() curve intentionally creates discrete jumps rather than a smooth path.

The example pauses real CSS animations and sets their currentTime for reproducible reads. For movement from 0 to 100px in one second, 250ms gives 25.00px with linear but 40.85px with ease. steps(4,end) gives 0.00px at 240ms and 25.00px at 260ms. Those are measured transform positions; changing the curve has not changed the one-second duration.

A second animation places steps(2,end) at 0% and linear at 50%, overriding the element’s ease-in. Reads at 125,250,750ms are 0.00,25.00,75.00px. Its 100% step-start declaration adds no new interval. The example also rejects a Bézier with X=2. Static, precisely sampled positions do not measure frame smoothness or motion accessibility; respect reduced-motion preferences in an actual interface.

Examples

const style=document.createElement('style');style.textContent='@keyframes move{from{transform:translateX(0)}to{transform:translateX(100px)}} @keyframes segments{0%{transform:translateX(0);animation-timing-function:steps(2,end)}50%{transform:translateX(50px);animation-timing-function:linear}100%{transform:translateX(100px);animation-timing-function:step-start}}';document.head.append(style);
const sample=(name,easing,ms)=>{const box=document.createElement('div');box.style.animation=name+' 1s '+easing+' both paused';document.body.append(box);getComputedStyle(box).transform;box.getAnimations()[0].currentTime=ms;const x=new DOMMatrix(getComputedStyle(box).transform).m41;box.remove();return x.toFixed(2)};
const linear=sample('move','linear',250),ease=sample('move','ease',250),steps=sample('move','steps(4,end)',240),stepsAfter=sample('move','steps(4,end)',260);
const segments=[125,250,750].map(t=>sample('segments','ease-in',t)).join(',');
console.log('linear250='+linear+'; ease250='+ease+'; steps240and260='+steps+','+stepsAfter+'; segment125250750='+segments+'; badBezier='+CSS.supports('animation-timing-function','cubic-bezier(2,0,1,1)'));

Result

linear250=25.00; ease250=40.85; steps240and260=0.00,25.00; segment125250750=0.00,25.00,75.00; badBezier=false

Executed in Chromium 157.0.8103.51. The Web Animations API is used only to pause and seek the CSS animation; its easing is defined in CSS, not replaced by a JavaScript calculation.

Sources