How to set the size of the controlling corners of a Circle using FabricJS?

In this tutorial, we are going to learn how to set the size of the controlling corners of a Circle using FabricJS. The controlling corners of an object allow us to scale, stretch or change its position. We can customize our controlling corners in many ways such as adding a specific colour to it, changing its size etc. We can change the size by using the cornerSize property.

Syntax

new fabric.Circle({ cornerSize: Number }: Object)

Parameters

  • options (optional) ? This parameter is an Object which provides additional customizations to our circle. Using this parameter, properties such as colour, cursor, stroke width and a lot of other properties can be changed related to the object of which cornerSize is a property.

Options Keys

  • cornerSize ? This property accepts a Number which allows us to manipulate the size of the controlling corners of a selected object. Its default value is 13.

Example 1: Default Corner Size

Let's see a code that depicts the default size of the controlling corners of a circle object when it is actively selected.

<!DOCTYPE html>
<html>
   <head>
      <!-- Adding the Fabric JS Library-->
      <script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/510/fabric.min.js"></script>
   </head>

   <body>
      <h2>Default controlling corners size</h2>
      <p>Select the object and notice the size of its controlling corners. This is the default appearance. Here we haven't used the <b>cornerSize</b> property.</p>
      <canvas id="canvas"></canvas>

      <script>
         // Initiate a canvas instance
         var canvas = new fabric.Canvas("canvas");
         var cir = new fabric.Circle({
            left: 215,
            top: 100,
            fill: "white",
            radius: 50,
            stroke: "#c154c1",
            strokeWidth: 5,
            borderColor: "#daa520",
            cornerColor: "rgb(255,20,147)"
         });

         // Adding it to the canvas
         canvas.add(cir);
         canvas.setWidth(document.body.scrollWidth);
         canvas.setHeight(250);
      </script>
   </body>
</html>

Example 2: Custom Corner Size

In this example, we are passing the cornerSize property as key with a value of 7. We can see how that changes the size of our controlling corners when the circle object is selected.

<!DOCTYPE html>
<html>
   <head>
      <!-- Adding the Fabric JS Library-->
      <script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/510/fabric.min.js"></script>
   </head>

   <body>
      <h2>Custom controlling corners size</h2>
      <p>Select the object and notice the size of its controlling corners. Here we have set the <b>cornerSize</b> at 7.</p>
      <canvas id="canvas"></canvas>

      <script>
         // Initiate a canvas instance
         var canvas = new fabric.Canvas("canvas");
         var cir = new fabric.Circle({
            left: 215,
            top: 100,
            fill: "white",
            radius: 50,
            stroke: "#c154c1",
            strokeWidth: 5,
            borderColor: "#daa520",
            cornerColor: "rgb(255,20,147)",
            cornerSize: 7
         });

         // Adding it to the canvas
         canvas.add(cir);
         canvas.setWidth(document.body.scrollWidth);
         canvas.setHeight(250);
      </script>
   </body>
</html>

Key Points

  • The cornerSize property accepts numeric values to control corner handle size
  • Default corner size is 13 pixels
  • Smaller values create more precise corner handles
  • The property affects all eight corner handles uniformly

Conclusion

The cornerSize property in FabricJS provides fine control over the controlling corners appearance. By adjusting this value, you can create more user-friendly interfaces with appropriately sized corner handles for your canvas objects.

Updated on: 2026-03-15T23:19:00+05:30

599 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements