How to disable the selectability of Circle using FabricJS?

In this tutorial, we are going to learn how to disable selectability of a Circle using FabricJS. Circle is one of the various shapes provided by FabricJS. In order to create a circle, we will have to create an instance of fabric.Circle class and add it to the canvas. In order to modify an object, we have to select it in FabricJS. However, we can change this behaviour by using the selectable property.

Syntax

new fabric.Circle({ selectable: Boolean }: 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 selectable is a property.

Options Keys

  • selectable ? This property accepts a Boolean value. When a 'false' value is assigned to it, the object cannot be selected for modifications. Its default value is True.

Example 1: Default Behavior (Selectable = True)

Let's see an example to understand how the object behaves when by default the selectable property is set to True. We are allowed to select an object, move it around the canvas and make modifications to it when the selectable property is set to true.

<!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 Selectable Behavior</h2>
      <p>Click on the circle to select it. You can move it around freely.</p>
      <canvas id="canvas" width="400" height="250"></canvas>

      <script>
         // Initiate a canvas instance
         var canvas = new fabric.Canvas("canvas");
         var circle = new fabric.Circle({
            left: 115,
            top: 50,
            radius: 50,
            fill: "#85bb65"
         });
         canvas.add(circle);
      </script>
   </body>
</html>

Example 2: Disabling Selectability

In this example, we are assigning a False value to the selectable property. This means that we can no longer select the circle object for modifications.

<!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>Disabling Circle Selectability</h2>
      <p>Try clicking on the circle - it cannot be selected because selectable is set to false.</p>
      <canvas id="canvas" width="400" height="250"></canvas>
   
      <script>
         // Initiate a canvas instance
         var canvas = new fabric.Canvas("canvas");
         var circle = new fabric.Circle({
            left: 115,
            top: 50,
            radius: 50,
            fill: "#85bb65",
            selectable: false
         });
         canvas.add(circle);
      </script>
   </body>
</html>

Key Points

  • The selectable property is true by default, allowing objects to be selected and modified
  • Setting selectable: false prevents the object from being selected or moved
  • Non-selectable objects can still be programmatically modified through code
  • This property is useful for creating background elements or decorative objects that shouldn't be interactive

Conclusion

The selectable property in FabricJS provides control over object interactivity. Setting it to false creates non-interactive elements while true (default) allows full user interaction with the circle object.

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

346 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements