ctx.beginPath(); ctx.lineWidth = "6"; ctx.strokeStyle = "red"; In the function sketch (), we use the following in-built methods to add functionality. The draw canvas updates. How to Draw a Semi-Circle using HTML and CSS ? How to insert spaces/tabs in text using HTML/CSS? HTML5 canvas draw rectangle with mouse. You can draw any kind of control you like on the canvas, and use the techniques described in Responding to Mouse and Touch Events on Canvas to determine if the input is on your custom control, but there is a faster and better way to implement most custom controls.. How to set input type date in dd-mm-yyyy format using HTML ? How to apply style to parent if it has child with CSS? functionName — This is the name of a function that will execute when the specified event occurs on the specified element. This function takes one parameter, the type of context 2d. Data Structures and Algorithms – Self Paced Course, Ad-Free Experience – GeeksforGeeks Premium, We use cookies to ensure you have the best browsing experience on our website. Each time you click a location on the canvas, a rectangular area around the mouse pointer will be cleared from the drawing. Skills: JavaScript, PHP, XML Here is the updated code to accomplish this: If you try out this code in the browser, you will see that when you click the canvas, a rectangular area around the mouse is cleared. How to select all child elements recursively using CSS? The HTML5