HTML Canvas Draw Bezier

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

Definition

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

Control points pull the curve but are not drawn automatically. After building the path, call stroke() or fill(). For a simpler one-control-point bend, use quadraticCurveTo().

Baseline · Widely available.

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

Cubic vs quadratic.

Cubic = two control points (bezierCurveTo). Quadratic = one control point (quadraticCurveTo). Prefer quadratic when one handle is enough.

Syntax

bezier.js
ctx.moveTo(startX, startY);
ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);

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

Parameters

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

ParameterDescriptionTry it
cp1x, cp1yFirst control point (pulls the curve near the start)Try it
cp2x, cp2ySecond control point (pulls the curve near the end)Try it
x, yEnd point of the curveTry it
Start pointNot an argument — use moveTo() or the previous path endTry it

Global Attributes

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

Live Preview

Drag the sliders to move both control points. Start and end stay fixed so you can see the pull clearly.

30
180

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

Canvas

bezierCurveTo(120, 30, 280, 180, 360, 110)

HTML Examples

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

Example 1 — Basic Cubic Curve

Set a start with moveTo, then add one bezierCurveTo.

HTML
<canvas id="demo" width="300" height="160" aria-label="Blue cubic Bezier curve"></canvas>
<script>
  const ctx = document.getElementById("demo").getContext("2d");
  ctx.beginPath();
  ctx.moveTo(30, 30);
  ctx.bezierCurveTo(120, 160, 180, 10, 270, 120);
  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, 30).
  3. Call bezierCurveTo(cp1, cp2, end) with two control points and the end.
  4. Stroke the path so the curve becomes visible.

Example 2 — Draw Control Points

Paint small dots so you can see how the handles pull the curve.

HTML
<canvas id="demo" width="300" height="160" aria-label="Bezier with control point markers"></canvas>
<script>
  const ctx = document.getElementById("demo").getContext("2d");
  const start = { x: 30, y: 40 };
  const cp1 = { x: 100, y: 140 };
  const cp2 = { x: 200, y: 20 };
  const end = { x: 270, y: 110 };

  ctx.beginPath();
  ctx.moveTo(start.x, start.y);
  ctx.bezierCurveTo(cp1.x, cp1.y, cp2.x, cp2.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(cp1.x, cp1.y, 4, 0, Math.PI * 2);
  ctx.arc(cp2.x, cp2.y, 4, 0, Math.PI * 2);
  ctx.fill();
</script>
Try It Yourself

How It Works

  1. Store points in objects so the curve and markers stay in sync.
  2. Stroke the Bézier first.
  3. Fill blue dots at start and end.
  4. Fill red dots at both control points (they do not sit 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="160" aria-label="Green wave of two Bezier curves"></canvas>
<script>
  const ctx = document.getElementById("demo").getContext("2d");
  ctx.beginPath();
  ctx.moveTo(20, 80);
  ctx.bezierCurveTo(60, 20, 100, 140, 140, 80);
  ctx.bezierCurveTo(180, 20, 220, 140, 280, 80);
  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 bezierCurveTo draws the first hump and ends at (140, 80).
  3. Second call continues from that end — no second moveTo.
  4. One stroke() paints the whole connected path.

Example 4 — Filled Soft Shape

Close the path and fill() to get a soft blob outline.

HTML
<canvas id="demo" width="300" height="160" aria-label="Filled purple Bezier shape"></canvas>
<script>
  const ctx = document.getElementById("demo").getContext("2d");
  ctx.beginPath();
  ctx.moveTo(150, 30);
  ctx.bezierCurveTo(230, 30, 260, 100, 150, 140);
  ctx.bezierCurveTo(40, 100, 70, 30, 150, 30);
  ctx.closePath();
  ctx.fillStyle = "#7c3aed";
  ctx.fill();
</script>
Try It Yourself

How It Works

  1. Start at the top with moveTo.
  2. Right side curve then left side curve back to the top.
  3. closePath() seals the outline (good habit for fills).
  4. fill() paints the interior.

Example 5 — Smooth Join Tip

Mirror control points around a join so two cubics look continuous.

HTML
<canvas id="demo" width="300" height="160" aria-label="Two smoothly joined Bezier curves"></canvas>
<script>
  const ctx = document.getElementById("demo").getContext("2d");
  const mid = { x: 150, y: 80 };
  // Handle before mid: (110, 40). Mirror after mid: (190, 120)
  ctx.beginPath();
  ctx.moveTo(20, 120);
  ctx.bezierCurveTo(60, 120, 110, 40, mid.x, mid.y);
  ctx.bezierCurveTo(190, 120, 240, 40, 280, 40);
  ctx.strokeStyle = "#ea580c";
  ctx.lineWidth = 3;
  ctx.stroke();
</script>
Try It Yourself

How It Works

  1. Pick a join point (mid) shared by both curves.
  2. First curve’s cp2 sits before mid.
  3. Second curve’s cp1 mirrors that handle past mid for a smoother tangent.
  4. Stroke once so the join looks like one continuous line.

Edge Cases & Pitfalls

Most Bezier bugs come from a missing start point or confusing control points with the curve itself.

start

Set a start with moveTo()

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

controls

Control points are not on the curve

They only pull the path. Draw helper dots if you need to debug the handles.

paint

bezierCurveTo() alone is invisible

It updates the path only. Call stroke() or fill() afterward.

choice

Prefer quadratic when one handle is enough

quadraticCurveTo() is simpler for gentle bends. Use cubic for S-shapes and finer control.

joins

Sharp corners at joins

If chained curves look kinked, mirror the control points around the join so tangents line up.

Browser Support

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

✓ Baseline · Widely available

bezierCurveTo()

Widely available since about July 2015. Chrome, Firefox, Safari, Edge, and Opera support cubic Bézier curves. Internet Explorer 9+ also supports bezierCurveTo().

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
bezierCurveTo() Widely supported

Bottom line: Safe to use for icons, smooth UI paths, and illustration-style curves on Canvas 2D.

Key Takeaways

  • Role: cubic curve = start + two control points + end.
  • Start: use moveTo() before the first bezierCurveTo().
  • Chain: the next curve continues from the previous end point.
  • Simpler option: one handle → quadraticCurveTo().

One line: moveTo → bezierCurveTo(cp1, cp2, end) → stroke() / fill().

Default CSS Settings

Bézier 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 cubic Bézier curve to the current path using two control points 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, so you can shape S-curves and more complex bends.
Common causes: forgetting moveTo() for the start, not calling stroke() or fill(), or placing both control points on the line between start and end.
No. Control points pull the curve but are not drawn unless you draw them yourself (for example with small arcs).
Yes. Each bezierCurveTo() starts from the previous end point. Call beginPath() when you want a separate shape.
Both refer to the same curve family. In code the method is bezierCurveTo (ASCII). Docs often write Bézier.

Next: Draw Paths

Combine lines, arcs, and curves into full reusable path workflows.

Canvas Draw Paths →

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