HTML <canvas> tag
HTML <canvas> tag
The <canvas>
tag is used to draw graphics via JavaScript.
This tag can also be used to draw graphs, combine photos, or create simple animations.
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas">Your browser does not support the HTML5 canvas tag.</canvas>
<script>
// Draw Rectangle
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.fillStyle = "#248f24";
ctx.fillRect(0, 0, 150, 100);
</script>
</body>
</html>
Tips
It is not recommended to learn canvas while taking html tutorial. Please navigate to Canvas tutorial after learning basic javascript.
Attributes
The following are the attributes of <canvas> tag. Also try Global attributes.
Attribute | Value | Explanation |
---|---|---|
width | px | Specifies the width of the canvas. |
height | px | Specifies the height of the canvas. |
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.