Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML tag

HTML tag

Example

Pass element to display a red rectangle:

<

canvas

id

=

"

myCanvas

"

canvas

<

script

type

=

"

text/javascript

"

var canvas=document.getElementById('myCanvas'); var ctx=canvas.getContext('2d'); ctx.fillStyle='#FF0000'; ctx.fillRect(0,0,80,100);

script

Try it »


Browser support

Internet Explorer Firefox Opera Google Chrome Safari

IE 9, Firefox, Opera, Chrome, and Safari support tag.

**Note:** IE 8 and earlier versions of IE browsers do not support tag.


Tag Definition and Usage Notes

the tag draws graphics (such as charts and other images) via scripts (usually JavaScript).

The tag is only a graphics container; you must use scripts to draw the graphics.


Differences between HTML 4.01 and HTML5

The tag is new in HTML5.


Tips and Notes

Note: Any text in the element will be displayed in browsers that do not support it.

**Tip:** To learn about all the properties and methods of the canvas object, please refer toHTML Canvas Reference Manual.


property

New : New attribute in HTML5.

property Value Description
heightNew pixels Specifies the height of the canvas.
widthNew pixels Specifies the width of the canvas.

Global Attributes

The tag supports HTML Global Attributes.


Event attribute

The tag supports HTML Event Attributes.