How to create a canvas with a help cursor using FabricJS?

In this article, we are going to create a canvas with a help cursor using FabricJS. The question mark in a help pointer indicates that useful information for the user is present. It is also often accompanied by useful links and can be seen while using a new application. help is one of the native cursor style available which can be used in the FabricJS canvas too.

FabricJS provides various types of cursors like default, all-scroll, crosshair, col-resize, row-resize, etc., that reuse the native cursor under the hood. Each of these cursors look slightly different based on operating system.

Syntax

new fabric.Canvas(element: HTMLElement|String, { defaultCursor: String }: Object)

Parameters

  • element ? This parameter is the <canvas> element itself which can be derived using document.getElementById() or the id of the <canvas> element itself. The FabricJS canvas will be initialized on this element.

  • options (optional) ? This parameter is an Object which provides additional customizations to our canvas. Using this parameter color, cursor, border width and a lot of other properties can be changed related to the canvas, of which defaultCursor is a property with which we can set the type of cursor that we want.

Example 1: Basic Help Cursor

The defaultCursor property accepts a String which determines the name of the cursor to be used on the canvas. We will set it to help to use the help cursor. Let's see a code to create a canvas with a help cursor in FabricJS.

<!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>Canvas with a help cursor using FabricJS</h2>
   <p>Bring the cursor inside the canvas to see the changed shape of cursor</p>
   <canvas id="canvas"></canvas>
   <script>
      // Initiate a canvas instance
      var canvas = new fabric.Canvas("canvas", {
         defaultCursor: "help"
      });
      canvas.setWidth(document.body.scrollWidth);
      canvas.setHeight(250);
   </script>
</body>
</html>

Example 2: Help Cursor with Circle Object

In this example, we will add a circle to the canvas along with the help cursor to demonstrate how the cursor appears when interacting with objects.

<!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>Canvas with help cursor using FabricJS</h2>
   <p>Here we have added a circle to the canvas along with a help cursor</p>
   <canvas id="canvas"></canvas>
   <script>
      // Initiate a canvas instance
      var canvas = new fabric.Canvas("canvas", {
         defaultCursor: "help"
      });
      
      // Initiate a Circle instance
      var circle = new fabric.Circle({
         radius: 50,
         fill: "green",
         left: 100,
         top: 50
      });
      
      // Render the circle in canvas
      canvas.add(circle);
      canvas.setWidth(document.body.scrollWidth);
      canvas.setHeight(250);
   </script>
</body>
</html>

Key Points

  • The help cursor displays a question mark pointer, indicating interactive help is available
  • The defaultCursor property is set during canvas initialization
  • This cursor is useful for tutorial modes or help sections in applications
  • The appearance may vary slightly across different operating systems

Conclusion

The help cursor in FabricJS provides a clear visual indication to users that assistance or additional information is available. By setting the defaultCursor property to "help", you can enhance user experience in educational or tutorial applications.

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

565 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements