US Flag – Using Canvas Tag

The canvas tag is a new HTML tag which is used to draw graphics using JavaScript. You can learn more about the canvas tag and its basic usage here. Since it is a relatively new tag, it does not render in all the browsers. For those browsers which do not support the canvas tag,  you would need a fallback image or code inside the canvas tag.

Here is the code to draw the US flag using the canvas tag mostly following the specs for the flag. See the final image.

Open an editor and create a new HTML5 document. You can copy the following code and save it as canvas_demo.html.

Continue reading