The Wayback Machine - https://web.archive.org/web/20240907113803/https://www.geeksforgeeks.org/fabric-js/
Open In App

Fabric.js

Last Updated : 15 Mar, 2023
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Fabric.js is an open-source JavaScript canvas library, that provides the interactive object model built on top of the canvas element. It is also an SVG-to-canvas & canvas-to-SVG parser. It was made by Juriy Zaytsev and was first launched in 2010.

Object-based drawing is one of the sophisticated features that Fabric.js by default provides in addition to animations, scaling, and morphing.

Fabric.js Tutorial

 

Features of Fabric.js:

  • It provides a frame for all shapes. We can resize and rotate all the shapes and can customize the size of the frame.
  • This allows us to group multiple shapes into one.
  • Fabric.js allows touch support so apps made on Fabric.js runs smoothly on mobile browsers
  • Fast serialization is made possible by Fabric.js, allowing the conversion of canvas data to JSON format.

Reasons to learn Fabric.js:

Fabric.js is the easiest way to work with HTML5 canvas. Fabric.js also provides an interactive object model on top of the canvas element. Using Fabric.js we can create and populate objects. Fabric.js has the ability to freely move and manipulate objects on the canvas using the mouse pointer

Installation:

There are two methods to install Fabric.js

Method 1 (Install with NPM): To install Fabric.js, we just need to run the below command after that we need to navigate the required file in our HTML file.

npm install fabric --save

Method 2 (Install with Yarn): To install Fabric.js, we just need to run the below command after that we need to navigate the required file in our HTML file.

yarn add fabric

Method 3 (Using CDN link): We can simply use the below-mentioned links in the head section of our HTML file that will enable Fabric.js.

<script src=”https://cdnjs.cloudflare.com/ajax/libs/fabric.js/2.3.6/fabric.min.js”></script>

Example: In this example, we will set the background color of a canvas using Fabric.js

HTML




<!DOCTYPE html>
<html>
<head>
    <!-- Adding the FabricJS library -->
    <script src=
    </script>
</head>
  
<body>
    <div style="text-align: center; width: 500px;">
        <h1 style="color: green;">
            GeeksforGeeks
        </h1>
  
        <b>
            Fabric.js Example
        </b>
    </div>
  
    <canvas id="canvas" width="500" height="300"
        style="border:1px solid #000000">
    </canvas>
  
    <script>
  
        // Initiate a Canvas instance
        var canvas = new fabric.Canvas("canvas", {
                  
            // Set the background color
            // of the Canvas
            backgroundColor: "cyan"
        });
    </script>
</body>
</html>


Output:

Fabric.js

Fabric.js

Benefits of Fabric.js:

  • It offers a fast cross-browser experience. 
  • Its support also runs in strict mode. 
  • Fabric.js runs on a server under node.js.
  • It has friendly support for touch devices.

Fabric.js Complete References:

Recent articles on Fabric.js



Previous Article
Next Article

Similar Reads

Fabric.js Textbox opacity Property
In this article, we are going to see how to set the opacity of a Textbox canvas using FabricJS. The canvas Textbox means Textbox is movable and can be stretched according to requirement. Further, the Textbox can be customized when it comes to initial stroke color, height, width, fill color, or stroke width. Approach: To make it possible, we are goi
2 min read
How to remove borders of a canvas-type text using Fabric.js ?
In this article, we are going to see how to remove the borders of a canvas-like text using FabricJS. The canvas means text written is movable and can be stretched according to requirement. Further, the text itself cannot be edited like a textbox.Approach: To make it possible we are going to use a JavaScript library called FabricJS. After importing
2 min read
Fabric.js Textbox originX Property
In this article, we are going to see how to set the horizontal origin of a Textbox canvas object using FabricJS. The canvas Textbox means the Textbox is movable and can be stretched according to requirement. Further, the Textbox can be customized when it comes to initial stroke color, height, width, fill color, or stroke width. Approach: To make it
2 min read
Fabric.js Itext transparentCorners Property
Fabric.js is a JavaScript library that is used to work with canvas. The canvas Itext is one of the class of fabric.js that is used to create Itext instances. The canvas Itext means the Itext is movable and can be stretched according to requirements. In this article, we will be using the transparentCorners property to set if the corners are transpar
2 min read
How to add shadow to a canvas circle using Fabric.js ?
In this article, we are going to see how to add shadow to a canvas circle using FabricJS. The canvas means the circle is movable and can be stretched according to requirement. Further, the circle can be customized when it comes to initial stroke color, fill color, stroke width, or radius. Approach: To make it possible, we are going to use a JavaScr
2 min read
Fabric.js Circle flipY Property
In this article, we are going to see how to vertically flip a circle canvas using FabricJS. The canvas circle is movable and can be stretched according to requirements. Further, the circle can be customized when it comes to initial stroke color, height, width, fill color, or stroke width. To make it possible, we are going to use a JavaScript librar
2 min read
Fabric.js line lockScalingFlip Property
In this article, we are going to see if the option set to true will lock the flipping in a canvas line in FabricJS. The canvas line is movable and can be stretched according to the need. Further, the line can be customized when it comes to initial stroke color, height, width, fill color, or stroke width. To make this possible we are going to use a
2 min read
Fabric.js Polyline left Property
In this article, we are going to see how to set the left property of a Polyline canvas using FabricJS. The canvas Polyline means Polyline is movable and can be stretched according to requirement. Further, the Polyline can be customized when it comes to initial stroke color, height, width, fill color, or stroke width. To make it possible, we are goi
2 min read
Fabric.js Textbox strokeWidth Property
In this article, we are going to see how to set the stroke width of a canvas Textbox using FabricJS. The canvas Textbox means Textbox is movable and can be stretched according to requirement. Further, the Textbox can be customized when it comes to initial stroke color, height, width, fill color, or stroke width. To make it possible, we are going to
2 min read
Fabric.js Group fillRule Property
In this article, we are going to see how to set the fillRule of a Group of the canvas using Fabric.js. The Group in Fabric.js is movable and can be stretched according to requirements. Further, the Group can be customized when it comes to initial stroke color, height, width, fill color, or stroke width. To make it possible we are going to use a Jav
2 min read
Fabric.js Text objectCaching Property
In this article, we are going to see how to change the objectCaching of the text canvas using Fabric.js. The canvas means the text written is movable, rotatable, resizable, and can be stretched. Further, the text itself cannot be edited like a textbox. Approach: To make it possible, we are going to use a JavaScript library called Fabric.js. After i
2 min read
Fabric.js line selectable Property
In this article, we are going to use selectable property to set the selectability of the canvas line in FabricJS. The canvas line means the line is movable and can be stretched according to requirement. Further, the line can be customized when it comes to initial stroke color, height, width, fill color, or stroke width. Syntax: fabric.line({ select
2 min read
Fabric.js line scaleY Property
In this article, we are going to set the vertical scale of a canvas line in FabricJS. The canvas line means the line is movable and can be stretched according to requirement. Further, the line can be customized when it comes to initial stroke color, height, width, fill color, or stroke width. Syntax: fabric.line({ scaleY : number }); Approach: To m
2 min read
Fabric.js Line Class Complete Reference
Fabric.js is an open-source JavaScript canvas library, which provides the interactive object model built on top of the canvas element. It is also an SVG-to-canvas &amp; canvas-to-SVG parser. The canvas line means the line is movable and can be stretched according to requirement, &amp; contains the customizable option when it comes to initial stroke
2 min read
Fabric.js Textbox cornerStrokeColor Property
In this article, we are going to see how to set the stroke color of controlling corners of canvas Textbox using Fabric.js. The Textbox in Fabric.js is movable and can be stretched according to requirements. Further, the Textbox can be customized when it comes to initial stroke color, fill color, stroke width, or radius. To make it possible, we are
2 min read
Fabric.js Image padding Property
Fabric.js is a JavaScript library that is used to work with canvas. The canvas Image is one of the classes of Fabric.js that is used to create Image instances. The Image in Fabric.js is movable and can be stretched according to requirement. In this article, we will be using the padding property to set the padding of the canvas Image. Approach: Firs
2 min read
Fabric.js | Text visible Property
In this article, we are going to see how to toggle the visibility of a text canvas using FabricJS. The canvas means text written is movable, rotatable, resizable, and can be stretched. But in this article, we will toggle the visibility of the text. Further, the text itself cannot be edited like a textbox.Approach: To make it possible, we are going
2 min read
Fabric.js Polygon minScaleLimit Property
In this article, we are going to see how to set the minimum scale limit of a canvas polygon using FabricJS so that the size of the polygon cannot be scaled-down than that limit. The canvas polygon means the polygon is movable and can be stretched according to requirement. Further, the polygon can be customized when it comes to initial stroke color,
2 min read
Fabric.js Path borderDashArray Property
In this article, we are going to see how to set the borderDashArray of a Path using Fabric.js. The Path in Fabric.js is movable and can be stretched according to requirements. Further, the Path can be customized when it comes to initial stroke color, height, width, fill color, or stroke width. To make it possible we are going to use a JavaScript li
2 min read
Fabric.js Itext borderDashArray Property
In this article, we will be using the borderDashArray property that is used to set the dash pattern of the border in a canvas Itext. Fabric.js is a JavaScript library that is used to work with canvas. The canvas Itext is one of the class of fabric.js that is used to create Itext instances. The canvas Itext means the Itext is movable and can be stre
2 min read
Fabric.js easeOutElastic() Method
In animation and games, it can be seen that many objects are moving from one point to another linearly. But after using the Easing function, the object's way of progressing can take a different natural and interesting shape. Easing functions is the rate of change of a parameter over time. It is those kinds of equations that move slowly at the start
3 min read
Fabric.js easeOutCubic() Method
In animation and games, it can be seen that many objects are moving from one point to another linearly. But after using the Easing function, the object's way of progressing can take a different natural and interesting shape. Easing functions is the rate of change of a parameter over time. It is that kind of equations that moves slowly at the start
3 min read
Fabric.js camelize() Method
The camelize() method used to camelize a specified string. Syntax: camelize(string) Parameters: This method accepts a parameter as mentioned above and described below: string: This parameter holds the string to camelize. Return Value: This method returns the camelized version of the string. Example 1: C/C++ Code &lt;!DOCTYPE html&gt; &lt;html&gt;
1 min read
How to create a simple editable canvas textbox using Fabric.js?
In this article, we are going to create a canvas textbox using Fabric.js. The canvas means text written in the Textbox is movable and can be stretched according to requirement. Further, the text itself can be edited into anything else too because it is a textbox. Creating structure: To make this possible we are going to use a JavaScript library cal
2 min read
How to create a canvas circle using Fabric.js ?
In this article, we are going to see how to create a canvas circle using FabricJS. The canvas means the circle is movable and can be stretched according to requirement. Further, the circle can be customized when it comes to initial stroke color, fill color, stroke width, or radius. Approach: To make it possible we are going to use a JavaScript libr
2 min read
How to create a canvas ellipse using Fabric.js ?
In this article, we are going to see how to create a canvas ellipse using FabricJS. The canvas means the ellipse is movable and can be stretched according to requirements. Further, the ellipse can be customized when it comes to initial stroke color, fill color, stroke width, or radius. Approach: To make it possible we are going to use a JavaScript
2 min read
How to create a canvas polygon using Fabric.js ?
In this article, we are going to see how to create a canvas polygon using FabricJS. The canvas means the polygon is movable and can be stretched according to requirements. Further, the polygon can be customized when it comes to the initial fill color and its coordinates. Approach: To make it possible we are going to use a JavaScript library called
2 min read
How to rotate a text canvas using Fabric.js ?
In this article, we are going to see how to rotate a text canvas using FabricJS. The canvas means text written is movable and can be stretched according to requirement. Further, the text itself cannot be edited like a textbox.Approach: To make it possible, we are going to use a JavaScript library called FabricJS. After importing the library using C
2 min read
How to create a rectangle canvas using Fabric.js ?
In this article, we are going to create a canvas rectangle using FabricJS. The canvas rectangle means rectangle is movable and can be stretched according to requirement. Further, the rectangle can be customized when it comes to initial stroke color, height, width, fill color or stroke width. Approach: To make this possible we are going to use a Jav
2 min read
How to change font-family of a text canvas using Fabric.js ?
In this article, we are going to see how to change the font-family of a text canvas using FabricJS. The canvas means text written is movable and can be stretched according to requirement. Further, the text itself cannot be edited like a textbox.To make it possible we are going to use a JavaScript library called FabricJS. After importing the library
2 min read
Article Tags :