HTML - <canvas> Tag


Advertisements


Description

The HTML <canvas> tag is for drawing graphics, animations etc using scripting.

Example

Live Demo
<!DOCTYPE html>
<html>

   <head>
      <title>HTML Canvas Tag</title>
   </head>

   <body>
      <canvas id = "newCanvas">Your browser does not support canvas tag.</canvas>
      <script>
         var c = document.getElementById('newCanvas');
         var ctx = c.getContext('2d');
         ctx.fillStyle = '#00FD00';
         ctx.fillRect(0,0,200,60);
      </script>
   </body>

</html>

This will produce the following result −

Global Attributes

This tag supports all the global attributes described in HTML Attribute Reference

Specific Attributes

The HTML <canvas> tag also supports the following additional attributes −

Attribute Value Description
height html-5 pixels Specifies height of the canvas.
width html-5 pixels Specifies width of the canvas.

Event Attributes

This tag supports all the event attributes described in HTML Events Reference

Browser Support

Chrome Firefox IE Opera Safari Android
Yes Yes Yes Yes Yes ?

html_tags_reference.htm

Advertisements