×
   ❮     
HTML CSS MySql Javascript SQL PYTHON JAVA C++ C# BOOTSTRAP REACT XML NODEJS ANGULAR DJango Rust Android VUE
     ❯   

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 »

Hey there! Let's go for Learn fasta then! It is more than just coding; it is to have the superpower that can solve any problem. Through simple and easy-to-grasp examples you will sail through the learning process. In addition, it is not just about coding– you will acquire competencies on how to solve complex problems, analyze data, and come up with efficient solutions. Shall we start this wonderful journey together! learnfasta.com terms of use, Copyright 2025 All Rights Reserved.