title: html5 canvas - does the width/height need to be defined inline?
body: <p>I've been messing around with HTML5 / Javascript and found something I don't understand.</p>
  
  <p>I was trying to write some basic routines for working with the HTML5 canvas, and found that the drawImage function wasn't drawing anything. Figuring it was my code, I used code from an existing tutorial, namely <a href="http://www.html5canvastutorials.com/tutorials/html5-canvas-images/" rel="nofollow">HTML5 Canvas Image Tutorial</a>. When I included the Javascript code therein externally (i.e. as a separate file), I still wasn't seeing my image drawn to the canvas.</p>
  
  <p>From there, I copied the complete source, found <a href="http://www.html5canvastutorials.com/demos/tutorials/html5_canvas_images/" rel="nofollow">here</a>, verbatim, and it did work. I started messing around to figure out why this worked but mine didn't.</p>
  
  <p>I found that the difference was that the verbatim code defined the width and height of the canvas inline. I prefer to separate styling out of HTML and into CSS. The code worked if I did:</p>
  
  <pre><code>&lt;canvas id = "myCanvas" width = "600" height = "400"&gt;&lt;/canvas&gt;
  </code></pre>
  
  <p>but did not work if I defined the canvas width and height in an external CSS stylesheet.</p>
  
  <p>I did determine that one of my problems was that I was including the stylesheet after the Javascript file; before doing that, my image did not appear at all, even after confirming via an alert() function that the code inside the image onload handler was firing. After changing the order in which the files were included, my image did appear, but was scaled weirdly, as if the CSS styling was ignored.</p>
  
  <p>Why is this? Am I missing something regarding the order in which canvas properties are defined via CSS? Why does Javascript ignore the CSS styling in this case? In case it's at all relevant, I've tried this in the latest versions of both Chrome and Firefox.</p>