Canvas Draw Quadratic

What You’ll Learn
quadraticCurveTo() draws a smooth curve using a single control point. It’s a great next step after straight lines and paths.
Once you understand the control point, you can build waves, callouts, icons, and smooth UI shapes.
⚡ Quick Reference
ctx.quadraticCurveTo(cpX, cpY, x, y);moveTo(startX, startY)Curve draws from the current point
cpX, cpYBends the curve
x, yWhere the curve finishes
👀 Live Preview — Drag the Control Point
Drag the green control point and see how the curve bends. The dashed helper lines show how the control point pulls the curve.
Hint: The control point usually isn’t on the curve. It influences the curve’s tangent direction at the start and end.
Basic Quadratic Curve
This mirrors the legacy example: a curve from left to right pulled upward by a control point.
const canvas = document.getElementById('myCanvas');
const ctx = canvas.getContext('2d');
ctx.beginPath();
ctx.moveTo(20, 100);
ctx.quadraticCurveTo(100, 20, 200, 100);
ctx.strokeStyle = '#0f172a';
ctx.lineWidth = 3;
ctx.stroke();Wave (Two Quadratic Segments)
Longer curves are usually built from multiple quadratic segments. Keep control points aligned for smooth tangents.
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.beginPath();
ctx.moveTo(40, 120);
// up
ctx.quadraticCurveTo(120, 40, 200, 120);
// down
ctx.quadraticCurveTo(280, 200, 360, 120);
ctx.strokeStyle = '#2563eb';
ctx.lineWidth = 6;
ctx.lineCap = 'round';
ctx.stroke();💡 Best Practices
Do
- Call
moveTo()first to set the curve start - Use helper lines while designing curves (like this page’s preview)
- Use multiple segments for long curves and keep tangents smooth
- Use
lineCap = 'round'for nicer endpoints - Use
beginPath()to prevent accidental connections
Don’t
- Assume the control point lies on the curve
- Forget
stroke()/fill()(paths don’t render by default) - Accidentally continue old shapes without
beginPath() - Use quadratic curves for complex shapes where cubic is easier
- Hardcode many magic numbers without extracting constants for readability
❓ Frequently Asked Questions
quadraticCurveTo().moveTo().beginPath(), your coordinates, and that you called stroke() or fill() with visible styles.Next: Draw Rectangles
Learn the fastest way to draw rectangles and how fill/stroke styles apply.
4 people found this page helpful
