HTML Canvas tag
Canvas tag in HTML:
The "Canvas" tag in HTML is used to create a drawing place or a region where you may render images, animations, or interactive visible content material using JavaScript.
Example
The "Canvas" tag is sort of a blank digital canvas in which you can draw, paint, and create visual elements the use of code.
Below example show "Canvas" tag to draw a simple rectangle:
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Canvas Drawing Example</title>
<style>
body {
font-family: 'Arial', sans-serif;
text-align: center;
margin-top: 50px;
font-size: 18px;
}
canvas {
border: 2px solid #3498db; /* Blue color for canvas border */
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); /* Box shadow for a subtle lift */
}
</style>
</head>
<body>
<canvas id="myCanvas" width="150" height="150"></canvas>
<script>
// Get the canvas element
var canvas = document.getElementById("myCanvas");
// Get the drawing context
var ctx = canvas.getContext("2d");
// Draw a rectangle
ctx.fillStyle = "#3498db"; /* Blue color for the rectangle */
ctx.fillRect(10, 10, 150, 80);
</script>
</body>
</html>
Try it Yourself »