Interview Questions

HTML5 Canvas

Canvas is used for rendering Graphs, graphics and other visual images

Global Attributes:

width
height

Example:

<!DOCTYPE html>
<html>

<head>
<title>Canvas Demo</title>
</head>

<body>

<canvas id="techDiveDemoCanvas" width="200" height="200" style="border:1px solid red">
HTML5 Canvas Not Supported
</canvas>

<script>
    var canvasElement = document.getElementById("techDiveDemoCanvas");
    var context = canvasElement.getContext("2d");
    context.fillRect(0, 0, 150, 100);
</script>

</body>
</html>