Draw Quadratic Curve in HTML5

The quadratic curve requires ending and control points and starting points will be current point. If current point is not defined then you can use the beginPath and moveTo methods to set a starting point.

quadratic curve in html5 canvas
We use the quadraticCurveTo method to draw a quadratic curve.

ctx.quadraticCurveTo(cpx1, cpy1, x, y);

x and y are the control points and cpx1 and cpy1 are the control points.


The following code example uses quadraticCurveTo to draw an arc.

  <title>Draw Arc</title>
    <style type="text/css">
        #MyCanvas {border:1px solid black;}
  <script type="text/javascript">
      function drawGradient() {
          var ctx;
          var canvas = document.getElementById("MyCanvas");
          if (canvas.getContext) {
              ctx = canvas.getContext("2d");
              // Draw a quadratic curve .
              ctx.lineWidth = "2";
              ctx.strokeStyle = "black";
              ctx.moveTo(100, 150);
              ctx.quadraticCurveTo(150, 50, 250, 150);
<body onload="drawGradient();">
  <canvas id="MyCanvas" width="300" height="200">
  This browser or document mode doesn't support canvas object</canvas>