The Canvas element is part of HTML5 which allows dynamic, scriptable rendering of 2D shapes and bitmap images. A canvas is a rectangular area, and you can control every pixel of the canvas. It does not have a built in scene graph because it is a low level procedural model that updates a bit map.
Canvas consists of a drawable region defined in HTML code with height and width attributes.Canvas includes some anticipated uses like building graphs, animations, games, and image composition.
How to create Canvas Element
You have to add <canvas> element to your HTML document and specify the id, width, and height of the element to create a canvas context on your page like so:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>
<body>
<canvas id="myCanvas" width="300" height="150">
Fallback content, in case the browser does not support Canvas.
</canvas>
</body>
</html>
Draw canvas using JavaScript
JavaScript code may access the area through a full set of drawing functions similar to other common 2D APIs because canvas element has no drawing abilities of its own.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>
<body>
<canvas id="myCanvas" width="200" height="100" style="border:1px solid #c3c3c3;">
Your browser does not support the canvas element.
</canvas>
<script type="text/javascript">
var c=document.getElementById("myCanvas");
var cxt=c.getContext("2d");
cxt.fillStyle="#FF0000";
cxt.fillRect(0,0,150,75);
</script>
</body>
</html>
Summary
Canvas is one of the most interesting HTML 5 features, and now used within most modern Web browsers. It provides all you need to create games, user interface enhancements, and other things besides.