canvas height Attribute - HTML CSS HTML Tag

HTML CSS examples for HTML Tag:canvas

Description

The height attribute specifies the height of the <canvas> element, in pixels.

Attribute Values

Value Description
pixels Specifies the height of the canvas, in pixels (e.g. "100"). Default height is "150"

A <canvas> element with a height and width of 200 pixels:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<canvas id="myCanvas" width="200" height="200" style="border:1px solid">
Your browser does not support the HTML5 canvas tag.
</canvas><!--from  w  w  w .  j a  v  a  2 s.  c  o  m-->

<script>

var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.fillStyle = "red";
ctx.fillRect(50, 50, 100, 100);

</script>
</body>
</html>

Related Tutorials