HTML canvas bezierCurveTo() method

Definition and usage

bezierCurveTo() method to add a point to the current path by using the specified control points of the cubic Bezier curve.

Hint:Three Bezier curves require three points. The first two points are used as control points in the cubic Bezier calculation, and the third point is the end point of the curve. The starting point of the curve is the last point in the current path. If the path does not exist, please use beginPath() and moveTo() method to define the starting point.

Cubic Bezier Curve
  • Starting point: moveTo(20,20)
  • Control point 1: bezierCurveTo(20,100,200,100,200,20)
  • Control point 2: bezierCurveTo(20,100,200,100,200,20)
  • End point: bezierCurveTo(20,100,200,100,200,20)

Hint:Please see quadraticCurveTo() method. It has one control point instead of two.

Example

Draw a cubic Bezier curve:

Your browser does not support the HTML5 canvas tag.

JavaScript:

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.moveTo(20,20);
ctx.bezierCurveTo(20,100,200,100,200,20);
ctx.stroke();

Try It Yourself

Syntax

context.bezierCurveTo(cp1x,cp1y,cp2x,cp2y,x,y);

Parameter Value

Parameters Description
cp1x The x-coordinate of the first Bezier control point.
cp1y The y-coordinate of the first Bezier control point.
cp2x The x-coordinate of the second Bezier control point.
cp2y The y-coordinate of the second Bezier control point.
x The x-coordinate of the endpoint.
y The y-coordinate of the endpoint.

Browser Support

The numbers in the table indicate the first browser version that fully supports this property.

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
4.0 9.0 3.6 4.0 10.1

Note:Internet Explorer 8 and earlier versions do not support the <canvas> element.