How to hide the controlling borders of an Ellipse using FabricJS?

In this tutorial, we are going to learn how to hide the controlling borders of an Ellipse using FabricJS. Ellipse is one of the various shapes provided by FabricJS. In order to create an ellipse, we will have to create an instance of fabric.Ellipse class and add it to the canvas. We can customize our controlling borders in many ways such as adding a specific color to it, a dash pattern etc. However, we can also eliminate the borders completely by using the hasBorders property.

Syntax

new fabric.Ellipse({ hasBorders: Boolean }: Object)

Parameters

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

Options Keys

  • hasBorders ? This property accepts a Boolean value which when set to False, the controlling borders will not be rendered. The default value is True.

Example 1: Default Appearance of Controlling Borders

The following example shows the default appearance of controlling borders of an Ellipse. Since the default value of hasBorders property is "true", the borders are rendered on selecting the ellipse object.

<!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 Borders</h2>
      <p>Select the object to see the controlling borders. This is the default behavior.</p>
      <canvas id="canvas"></canvas>

      <script>
         // Initiate a canvas instance
         var canvas = new fabric.Canvas("canvas");

         // Initiate an ellipse instance
         var ellipse = new fabric.Ellipse({
            left: 105,
            top: 100,
            fill: "white",
            rx: 100,
            ry: 60,
            stroke: "#c154c1",
            strokeWidth: 5,
         });

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

Example 2: Hiding Borders with hasBorders Property

If the hasBorders property is assigned a "false" value, the borders will no longer be rendered. This means that when we select our ellipse object, the controlling borders will be hidden.

<!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>Hidden Controlling Borders</h2>
      <p>Select the object. The controlling borders are hidden because hasBorders is set to false.</p>
      <canvas id="canvas"></canvas>

      <script>
         // Initiate a canvas instance
         var canvas = new fabric.Canvas("canvas");

         // Initiate an ellipse instance
         var ellipse = new fabric.Ellipse({
            left: 105,
            top: 100,
            fill: "white",
            rx: 100,
            ry: 60,
            stroke: "#c154c1",
            strokeWidth: 5,
            hasBorders: false,
         });

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

Key Points

  • The hasBorders property controls the visibility of selection borders around FabricJS objects
  • Setting hasBorders: false completely hides the controlling borders when the object is selected
  • This property is useful when you want to create a cleaner interface without visual selection indicators
  • The object remains selectable and manipulable even with hidden borders

Conclusion

The hasBorders property in FabricJS provides an easy way to hide controlling borders of ellipse objects. Set it to false to create a cleaner canvas interface while maintaining object functionality.

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

295 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements