<canvas>
//here is an example of a basic, empty canvas
<canvas id="myCanvas" width="200" height="100" style="border:1px solid #000000;">
</canvas>
//Draw a Circle
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.arc(95, 50, 40, 0, 2 * Math.PI);
ctx.stroke();
//Draw Linear Gradient
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
// Create gradient
var grd = ctx.createLinearGradient(0, 0, 200, 0);
grd.addColorStop(0, "red");
grd.addColorStop(1, "white");
// Fill with gradient
ctx.fillStyle = grd;
ctx.fillRect(10, 10, 150, 80);
- Is used to draw graphics on a web page.
- Is only a container for graphics.
- You must use JavaScript to actually draw the graphics.
- Is a rectangular area on an HTML page.
- By default, a canvas has no border and no content.