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 called FabricJS and create a basic canvas structure.

  • Including FabricJS librarie: Importing the library using CDN

    <script src=””></script>

  • HTML code to create canvas structure: We will create a canvas block in the body tag which will contain our textbox. After this, we will initialize instances of Canvas and Textbox provided by FabricJS and render the Canvas on the Textbox as given in the example below.




    <!DOCTYPE hyml>
            <b>Creating cnavas-type textbox</b>
            <canvas id="canvas"



Design structure: In this section we will design the pre-created structure, and also add the functionality to move the canvas text around the canvas by using JavaScript.