You are here : htmlHTML 5canvas

<canvas> - HTML 5

The tag is used to draw graphics, on the fly, via scripting (usually JavaScript).

The tag is only a container for graphics, you must use a script to actually draw the graphics.

Attributes :

  • ​height (pixels) - Specifies the height of the canvas
  • width (pixels) - Specifies the width of the canvas


Syntax

<canvas id="myCanvas"></canvas>


Example

<canvas id="myCanvas"></canvas>
<script>
	var canvas = document.getElementById("myCanvas");
	var ctx = canvas.getContext("2d");
	ctx.fillStyle = "#FF0000";
	ctx.fillRect(0, 0, 80, 80);
</script>


Output / Return Value


Limitations

Available only to HTML 5.

JavaScript must be enabled to use.


Alternatives / See Also


Reference