HTML Canvas Draw Quadratic

Beginner
7 min read
Updated: Nov 2026
5 examples
Live preview

Definition

On an <canvas>, ctx.quadraticCurveTo() adds a quadratic Bézier curve to the current path. You give one control point and an end point. The start is the current path point (set with moveTo() or a previous segment).

One control point is enough for gentle arches and speech-bubble corners. For S-curves or independent start/end handles, use bezierCurveTo() (two control points).

Baseline · Widely available.

CanvasRenderingContext2D.quadraticCurveTo() is a stable Canvas 2D method across modern browsers since about July 2015.

Quadratic vs cubic.

Quadratic = one control point (quadraticCurveTo). Cubic = two control points (bezierCurveTo). Start with quadratic when learning curves.

Syntax

quadratic.js
ctx.moveTo(startX, startY);
ctx.quadraticCurveTo(cpx, cpy, x, y);

Always set a start with moveTo() (or continue from a previous segment). Then paint with stroke() and/or fill().

Parameters

Arguments for quadraticCurveTo() (Canvas 2D API):

ParameterDescriptionTry it
cpx, cpySingle control point that pulls the curveTry it
x, yEnd point of the curveTry it
Start pointNot an argument — use moveTo() or the previous path endTry it
ChainingNext quadraticCurveTo continues from the last endTry it

Global Attributes

The <canvas> tag also supports the Global Attributes in HTML.

Live Preview

Move the single control point and watch how the curve bends between fixed start and end points.

200
20

Blue = start/end. Red = control point. Dashed lines are guides only.

Canvas

quadraticCurveTo(200, 20, 360, 160)

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Basic Quadratic Curve

Set a start with moveTo, then add one quadraticCurveTo.

HTML
<canvas id="demo" width="300" height="160" aria-label="Blue quadratic curve"></canvas>
<script>
  const ctx = document.getElementById("demo").getContext("2d");
  ctx.beginPath();
  ctx.moveTo(30, 130);
  ctx.quadraticCurveTo(150, 20, 270, 130);
  ctx.strokeStyle = "#2563eb";
  ctx.lineWidth = 3;
  ctx.stroke();
</script>
Try It Yourself

How It Works

  1. Start a path with beginPath().
  2. Set the start with moveTo(30, 130).
  3. Call quadraticCurveTo(cpx, cpy, endX, endY) with one control point.
  4. Stroke the path so the curve becomes visible.

Example 2 — Draw the Control Point

Mark start, end, and the control point so the pull is obvious.

HTML
<canvas id="demo" width="300" height="160" aria-label="Quadratic with control point marker"></canvas>
<script>
  const ctx = document.getElementById("demo").getContext("2d");
  const start = { x: 40, y: 130 };
  const cp = { x: 150, y: 20 };
  const end = { x: 260, y: 130 };

  ctx.beginPath();
  ctx.moveTo(start.x, start.y);
  ctx.quadraticCurveTo(cp.x, cp.y, end.x, end.y);
  ctx.strokeStyle = "#0f172a";
  ctx.lineWidth = 2;
  ctx.stroke();

  ctx.fillStyle = "#2563eb";
  ctx.beginPath();
  ctx.arc(start.x, start.y, 4, 0, Math.PI * 2);
  ctx.arc(end.x, end.y, 4, 0, Math.PI * 2);
  ctx.fill();

  ctx.fillStyle = "#dc2626";
  ctx.beginPath();
  ctx.arc(cp.x, cp.y, 4, 0, Math.PI * 2);
  ctx.fill();
</script>
Try It Yourself

How It Works

  1. Store points so the curve and markers stay aligned.
  2. Stroke the quadratic first.
  3. Blue dots mark start and end.
  4. Red dot marks the control point (usually not on the curve).

Example 3 — Wave from Chained Curves

Each new curve starts where the last one ended.

HTML
<canvas id="demo" width="300" height="140" aria-label="Green wave of quadratic curves"></canvas>
<script>
  const ctx = document.getElementById("demo").getContext("2d");
  ctx.beginPath();
  ctx.moveTo(20, 70);
  ctx.quadraticCurveTo(60, 20, 100, 70);
  ctx.quadraticCurveTo(140, 120, 180, 70);
  ctx.quadraticCurveTo(220, 20, 280, 70);
  ctx.strokeStyle = "#16a34a";
  ctx.lineWidth = 3;
  ctx.stroke();
</script>
Try It Yourself

How It Works

  1. moveTo sets the left start of the wave.
  2. First curve arches up to the first mid point.
  3. Next calls continue from that end — no extra moveTo.
  4. One stroke() paints the whole connected path.

Example 4 — Soft Rounded Shape

Use four quadratics to round a speech-bubble style box.

HTML
<canvas id="demo" width="300" height="160" aria-label="Rounded bubble outline"></canvas>
<script>
  const ctx = document.getElementById("demo").getContext("2d");
  const x = 40, y = 40, w = 220, h = 80, r = 20;

  ctx.beginPath();
  ctx.moveTo(x + r, y);
  ctx.lineTo(x + w - r, y);
  ctx.quadraticCurveTo(x + w, y, x + w, y + r);
  ctx.lineTo(x + w, y + h - r);
  ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
  ctx.lineTo(x + r, y + h);
  ctx.quadraticCurveTo(x, y + h, x, y + h - r);
  ctx.lineTo(x, y + r);
  ctx.quadraticCurveTo(x, y, x + r, y);
  ctx.closePath();
  ctx.strokeStyle = "#7c3aed";
  ctx.lineWidth = 3;
  ctx.stroke();
</script>
Try It Yourself

How It Works

  1. Straight sides with lineTo.
  2. Each corner uses quadraticCurveTo with the corner as the control point.
  3. closePath() seals the outline.
  4. Stroke (or fill) the finished path.

Example 5 — Fill and Stroke an Arch

Close under the curve, then fill and stroke.

HTML
<canvas id="demo" width="300" height="160" aria-label="Filled orange quadratic arch"></canvas>
<script>
  const ctx = document.getElementById("demo").getContext("2d");
  ctx.beginPath();
  ctx.moveTo(40, 120);
  ctx.quadraticCurveTo(150, 20, 260, 120);
  ctx.lineTo(40, 120);
  ctx.closePath();
  ctx.fillStyle = "#fdba74";
  ctx.fill();
  ctx.strokeStyle = "#ea580c";
  ctx.lineWidth = 3;
  ctx.stroke();
</script>
Try It Yourself

How It Works

  1. Draw the arch with quadraticCurveTo.
  2. Close along the base so fill has a sealed area.
  3. fill() first, then stroke() for a clean border.
  4. Same path is used for both paints.

Edge Cases & Pitfalls

Most quadratic bugs come from a missing start point or placing the control on the chord.

start

Set a start with moveTo()

Without a current point, the curve may start at (0, 0). Always moveTo for a standalone curve.

control

The control point is usually not on the curve

It only pulls the path. Draw a helper dot when debugging.

paint

quadraticCurveTo() alone is invisible

Call stroke() or fill() after building the path.

choice

Need an S-curve? Use cubic

One control cannot bend both ends independently. Switch to bezierCurveTo().

corners

Rounded rects: control at the corner

A common pattern puts the control at the sharp corner and ends on the next side, as in Example 4.

Browser Support

ctx.quadraticCurveTo() is part of the Canvas 2D API in every modern browser.

✓ Baseline · Widely available

quadraticCurveTo()

Widely available since about July 2015. Chrome, Firefox, Safari, Edge, and Opera support quadratic curves. Internet Explorer 9+ also supports quadraticCurveTo().

98% Global support (approx.)
Google Chrome All modern
Full support
Mozilla Firefox All modern
Full support
Apple Safari All modern
Full support
Microsoft Edge All modern
Full support
Opera All modern
Full support
Samsung Internet All modern
Full support
Internet Explorer 9+
Supported
quadraticCurveTo() Widely supported

Bottom line: Safe to use for rounded UI shapes, simple arches, and learning curves before cubic Beziers.

Key Takeaways

  • Role: quadratic = start + one control point + end.
  • Start: use moveTo() before the first curve.
  • Chain: the next curve continues from the previous end.
  • Upgrade: need two handles → bezierCurveTo().

One line: moveTo → quadraticCurveTo(cp, end) → stroke() / fill().

Default CSS Settings

Quadratic drawing is a Canvas API concern. The <canvas> element still uses typical user-agent CSS:

default.css
canvas {
  display: inline;
}

Set bitmap size with HTML width/height. CSS-only sizing scales the bitmap and can blur curves.

Frequently Asked Questions

It adds a quadratic Bézier curve to the current path using one control point and an end point. The start is the current path point (often set with moveTo()).
quadraticCurveTo() uses one control point (simpler bends). bezierCurveTo() uses two control points for S-curves and finer shaping.
If the control point lies on the line between start and end, the curve looks straight. Move the control point off that line to bend it.
No. The control point pulls the curve but is not drawn unless you draw it yourself (for example with a small arc).
Yes. Each quadraticCurveTo() starts from the previous end point. Call beginPath() when you want a separate shape.
Use quadratic when one handle is enough. Switch to cubic (bezierCurveTo) when you need independent pull near the start and end.

Next: Draw Bezier

Add a second control point with bezierCurveTo() for S-curves and finer bends.

Canvas Draw Bezier →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful