The <canvas>
tag in HTML is used for drawing graphics using scripts, typically JavaScript. <canvas>
allows for the dynamic creation and manipulation of graphics, animations, charts, and other visualizations.
Example of using <canvas>
:
- Drawing a rectangle:
<canvas id="myCanvas" width="200" height="100" style="border:1px solid #000000;"></canvas> <script> var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d"); ctx.fillStyle = "#FF0000"; ctx.fillRect(0, 0, 150, 75); </script>
The <canvas>
tag is useful for creating interactive web applications that require advanced graphics, such as games, image editors, and data visualization tools.