What is the purpose of canvas in HTML?

Asked: Apr 15, 2023

Canvas is an element that is used for the graphics for the web page. It uses JavaScript to bring the graphics functionality live. It allows easy way to draw the graphics and use different types of tools to create drawing on the web page. Canvas is just a rectangular area that controls the pixel of every element that is used in the web page. Canvas uses methods like paths, circles, etc.

<canvas id="can" width="200" height="100"></canvas>

The canvas element includes id, width and height settings and with the javascript it gets used like:

<script type="text/javascript">var c=document.getElementById("can");var ctx=c.getContext("2d");ctx.fillStyle="#FF0000";ctx.fillRect(0,0,150,75);</script>

Asked by brijesh

Answers (0)

No answers yet. Be the first to answer!