HTML and CSS Reference
Example 1-2. HTML5 Hello World!
<title>CH1EX2: Hello World HTML Page With A DIV </title>
<div style="position: absolute; top: 50px; left: 50px;">
The style="position: absolute; top: 50px; left: 50px;" code is an example of inline
CSS in an HTML page. It tells the browser to render the content at the absolute position
of 50 pixels from the top of the page, and 50 pixels from the left of the page.
Our work with <canvas> will benefit from using the absolute positioning method with
<div> . We will place our <canvas> inside the <div> tag, and it will help us retrieve in-
formation, such as the relative position of the mouse pointer when it appears over a
The Document Object Model (DOM) and Canvas
The Document Object Model represents all the objects on an HTML page. It is
language- and platform-neutral, allowing the content and style of the page to be up-
The canvas element itself is accessible through the DOM in a web browser via the
Canvas 2D context, but the individual graphical elements created on Canvas are not
accessible to the DOM. As we stated earlier, this is because Canvas works in immediate
mode and does not have its own objects, only instructions on what to draw on any
Our first example will use the DOM to locate the <canvas> tag on the HTML5 page so
need to understand when we start using <canvas> : window and document .
The window object is the top level of the DOM. We will need to test this object to make
sure all the assets and code have loaded before we can start our Canvas applications.
The document object contains all the HTML tags that are on the HTML page. We will
need to look at this object to find the instance of <canvas> that manipulates with