canvas width Attribute - HTML CSS HTML Tag

HTML CSS examples for HTML Tag:canvas

Description

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

Attribute Values

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

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  www .j ava  2  s.co  m-->

<script>

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

</script>

</body>
</html>

Related Tutorials