How to set the color of controlling corners of Ellipse using FabricJS?

In this tutorial, we are going to set the color of controlling corners of Ellipse using FabricJS. The cornerColor property allows us to manipulate the color of the controlling corners when the object is active.

Syntax

new fabric.Ellipse({ cornerColor: String }: 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 the cornerColor is a property.

Option Keys

  • cornerColor ? This property accepts a String which allows us to assign a color to the controlling corners when the object is actively selected. It supports color names, hex values, RGB, and RGBA formats.

Example 1: Using Color Name

Passing cornerColor as key with a color name as value

The following example demonstrates how to change the color by using the cornerColor property. In this case, we have assigned the value "black" to the key which thus makes the controlling corners appear black.

<!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>How to set the color of controlling corners of Ellipse using FabricJS?</h2>
      <p>Select the object and observe the color of the controlling corners. Here we have used the <b>cornerColor</b> property to set the controlling corners black.</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: 215,
            top: 100,
            fill: "white",
            rx: 90,
            ry: 50,
            stroke: "#c154c1",
            strokeWidth: 5,
            borderColor: "#daa520",
            cornerColor: "black",
         });

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

Example 2: Using RGB Value

Assigning an RGB value to the cornerColor property

Instead of passing a simple color name as the String value to the key, we can also assign an RGB value. RGB stands for red, green, and blue values. Let us see a code example of how we can do that:

<!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>How to set the color of controlling corners of Ellipse using FabricJS?</h2>
      <p>Select the object and observe the color of the controlling corners. Here we have used the <b>cornerColor</b> property and passed an RGB value.</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: 215,
            top: 100,
            fill: "white",
            rx: 90,
            ry: 50,
            stroke: "#c154c1",
            strokeWidth: 5,
            borderColor: "#daa520",
            cornerColor: "rgb(255,20,147)",
         });

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

Supported Color Formats

The cornerColor property accepts various color formats:

  • Color names: "red", "blue", "black", "green"
  • Hex values: "#FF0000", "#00FF00", "#0000FF"
  • RGB values: "rgb(255, 0, 0)", "rgb(0, 255, 0)"
  • RGBA values: "rgba(255, 0, 0, 0.5)" (with transparency)

Conclusion

The cornerColor property in FabricJS allows you to customize the appearance of controlling corners when an ellipse is selected. You can use various color formats including color names, hex, RGB, and RGBA values to achieve the desired visual effect.

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

401 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements