How to add the HTML5 canvas element to a webpage
suggest changeHTML5 canvas …
- Is an HTML5 element.
- Is supported in most modern browsers (Internet Explorer 9+).
- Is a visible element that is transparent by default.
- Has a default width of 300px and a default height of 150px.
- Requires JavaScript because all content must be programmatically added to the canvas.
Example: Create an HTML5 canvas element using both HTML markup and JavaScript:
<!doctype html>
<html>
<head>
<style>
body{ background-color:white; }
#canvasHtml5{border:1px solid red; }
#canvasJavascript{border:1px solid blue; }
</style>
<script>
window.onload=(function(){
// add a canvas element using javascript
var canvas=document.createElement('canvas');
canvas.id='canvasJavascript'
document.body.appendChild(canvas);
}); // end $(function(){});
</script>
</head>
<body>
<!-- add a canvas element using html -->
<canvas id='canvasHtml5'></canvas>
</body>
</html>
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents