Working with the HTML5 Canvas: Listing 1.

Defining the canvas element in an HTML page.

<html>
<head>
  <title>Canvas Writer</title>
  <script type="text/javascript">
    window.onload = function () {
      var
        canvas = document.getElementById("canvas"),
        context = canvas.getContext("2d");
      };    
    </script>
</head>
<body>
    <canvas id="canvas" width="800" height="600">
    </canvas>
</body>

About the Author

John Papa is a Microsoft Regional Director and former Microsoft technical evangelist. Author of 100-plus articles and 10 books, he specializes in professional application development with Windows, HTML5, JavaScript, CSS, Silverlight, Windows Presentation Foundation, C#, .NET and SQL Server. Check out his online training with Pluralsight; find him at johnpapa.net and on Twitter at twitter.com/john_papa.