Custom Cubic Bezier Curves
What you'll learn: How to create your own timing functions using cubic-bezier() to craft unique, custom animation curves that go beyond the built-in presets.
Beyond the Built-In Options
You've learned that transition-timing-function controls how a transition progresses over time. While keywords like ease, linear, ease-in, and ease-out are convenient, they're just shortcuts for pre-defined cubic bezier curves. The real power comes when you create your own.
What is a Cubic Bezier Curve?
Think of it like drawing a smooth path between two points. A cubic bezier curve uses four values to define the shape of this path, controlling the acceleration and deceleration of your animation. The syntax looks like this:
.element {
transition-timing-function: cubic-bezier(x1, y1, x2, y2);
}
The four numbers represent two control points that "pull" the curve. The starting point (0, 0) and ending point (1, 1) are fixed—you only control the two middle points.
- x values must be between 0 and 1 (representing time)
- y values can go outside 0-1 (creating bounces or overshoots!)
Practical Example
.box {
transition-property: transform;
transition-duration: 0.5s;
transition-timing-function: cubic-bezier(0.68, -0.55, 0.27, 1.55);
}
.box:hover {
transform: translateX(200px);
}
This creates a bouncy effect where the element slightly overshoots before settling—notice the negative and >1 y-values creating that playful movement.
Tools to help: Browser DevTools often include visual cubic-bezier editors, and sites like cubic-bezier.com let you preview and fine-tune curves interactively.
Key Takeaway: The cubic-bezier() function lets you craft completely custom timing curves by specifying four control point values, enabling animations that bounce, overshoot, or follow any acceleration pattern you can imagine.