Canvas Draw Bezier

What You’ll Learn
Bezier curves are how you draw smooth curves on canvas. The curve is defined by a start point, an end point, and one or two control points that bend the curve.
Canvas supports both quadraticCurveTo() (1 control point) and bezierCurveTo() (2 control points).
⚡ Quick Reference
quadraticCurveTo(cp1x, cp1y, x, y)One control point, smoother than lines
bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y)Two control points, more flexibility
moveTo(startX, startY)Curves draw from the current point
👀 Live Preview — Move Control Points
Drag the green/orange control points to see how they bend the curve. Toggle between quadratic and cubic curves.
Hint: control points are usually not on the curve. They act like magnets that pull the curve and control its tangent direction near the endpoints.
Quadratic Bezier Curve
Quadratic curves use one control point. The curve starts at the last moveTo() position.
<canvas id="myCanvas" width="420" height="220"></canvas>
<script>
const canvas = document.getElementById('myCanvas');
const ctx = canvas.getContext('2d');
ctx.beginPath();
ctx.moveTo(50, 160); // start
ctx.quadraticCurveTo(160, 20, 320, 140); // control, end
ctx.strokeStyle = '#2563eb';
ctx.lineWidth = 4;
ctx.stroke();
</script>🧠 How it works
The control point (160, 20) pulls the curve upward. Moving it changes the curve’s bend and the tangent direction near the start/end.
Cubic Bezier Curve
Cubic curves use two control points, giving you more control over the shape.
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.beginPath();
ctx.moveTo(60, 170); // start
ctx.bezierCurveTo(
140, 10, // cp1
300, 220, // cp2
360, 70 // end
);
ctx.strokeStyle = '#0f172a';
ctx.lineWidth = 4;
ctx.stroke();💡 Best Practices
Do
- Always set a start point with
moveTo()before the curve - Use helper lines/points while designing a curve (like the live preview)
- Use cubic curves for complex shapes; quadratic is great for simple bends
- Use
lineJoin/lineCapfor smooth path rendering - Use multiple Bezier segments for longer paths (and keep tangents smooth)
Don’t
- Forget
beginPath()if you want a separate curve - Assume control points lie on the curve
- Use too many segments without simplifying (performance + maintainability)
- Ignore the current point; curves draw from wherever the pen is
- Mix up cp/end ordering (it changes the curve dramatically)
❓ Frequently Asked Questions
quadraticCurveTo() and bezierCurveTo().moveTo() before the curve.Continue with Lines & Paths
Learn how to draw clean paths using lines, joins, and strokes.
4 people found this page helpful
