Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

cubic-bezier() — custom easing curve

`cubic-bezier()` maps input progress to output progress using two control points of a cubic Bézier curve.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

cubic-bezier( [ <number [0,1]>, <number> ]#{2} )

cubic-bezier() maps input progress to output progress using two control points of a cubic Bézier curve.

The example pauses real animations halfway through time: cubic-bezier(0.25, 0.1, 0.25, 1) moves the element to 80.24px, while cubic-bezier(0.3, 1.5, 0.7, 1.5) reaches 125px, exposing permitted overshoot. cubic-bezier(-0.1, 0, 1, 1) is invalid because its first x coordinate lies outside the range.

Grammar: cubic-bezier( [ <number [0,1]>, <number> ]#{2} ).

Both control-point x coordinates must be in [0,1] so every time has one unambiguous output. y1 and y2 are not similarly bounded and may drive the value beyond its endpoints. Endpoints are fixed at (0,0) and (1,1); input progress is the curve’s x coordinate, not its parametric t.

Examples

const makeBox = () => { const box = document.createElement('div'); box.style.cssText = 'width:10px;height:10px'; document.body.append(box); return box; };
const sample = easing => {
  const box = makeBox();
  const animation = box.animate([{transform:'translateX(0px)'},{transform:'translateX(100px)'}],{duration:1000,fill:'both',easing});
  animation.pause(); animation.currentTime = 500;
  const matrix = new DOMMatrix(getComputedStyle(box).transform);
  animation.cancel(); box.remove();
  return matrix.m41;
};
const easeMid = sample('cubic-bezier(0.25,0.1,0.25,1)');
const overshootMid = sample('cubic-bezier(0.3,1.5,0.7,1.5)');
const invalidX = CSS.supports('animation-timing-function','cubic-bezier(-0.1,0,1,1)');
console.log('ease-mid=' + easeMid.toFixed(2) + '; overshoot-mid=' + overshootMid.toFixed(2) + '; invalid-x=' + invalidX);

Result

ease-mid=80.24; overshoot-mid=125.00; invalid-x=false

`cubic-bezier()` maps input progress to output progress using two control points of a cubic Bézier curve.

Sources