HTML <canvas> with width Attribute
You are Here:
HTML <canvas> with width Attribute
The width
attribute specifies the width of the <canvas> element, in pixel.
If width
attribute is not specified then the default value (300px) will be applied.
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="200" height="200" style="border:2px solid;">
Your browser does not support canvas tag.
</canvas>
<script>
//Draw rectangle inside square
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.fillStyle = "#248f24";
ctx.fillRect(23, 50, 150, 100);
</script>
</body>
</html>
Attribute Value
Value | Explanation |
---|---|
px | Specifies the width of the canvas. The default value is 300px. |
Reminder
Hi Developers, we almost covered 99.5% of HTML Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in HTML.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.