HTML CSS examples for HTML Tag:canvas
The <canvas> element marks a region which can be used to draw graphics using JavaScript.
Placement | Inline |
---|---|
Content | Inline, and text |
Start/End Tag | Start tag: required, End tag: required |
Version | New in HTML5 |
The following table shows the attributes that are specific to the <canvas> tag.
Attribute | Value | Description |
---|---|---|
width | pixels | Sets the width of the canvas. |
height | pixels | Sets the height of the canvas. |
<!DOCTYPE html> <html lang="en"> <head> <title>Example of HTML canvas Tag</title> <style type="text/css"> canvas{<!-- w w w . ja v a 2 s .c o m--> border: 1px solid #000; } </style> </head> <body> <canvas id="myCanvas" width="300" height="200"></canvas> <script type="text/javascript"> window.onload = function(){ var canvas = document.getElementById("myCanvas"); var context = canvas.getContext("2d"); context.moveTo(50, 150); context.lineTo(250, 50); context.stroke(); }; </script> </body> </html>