Q:
What is the purpose of canvas in HTML?
Answer
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. The canvas element will be used as follows:
<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>
View answer
Workspace
Report Error
Discuss