- ✕This summary was generated using AI based on multiple online sources. To view the original source information, use the "Learn more" links.
The HTML <canvas> element is a powerful tool for drawing graphics on a web page using JavaScript. It can be used for a variety of purposes, such as creating animations, game graphics, data visualizations, and photo manipulations. The <canvas> element itself is just a container for graphics; all the drawing must be done using JavaScript.
Basic Usage
To use the <canvas> element, you need to include it in your HTML and then use JavaScript to draw on it. Here is a basic example:
<canvas id="myCanvas" width="200" height="100" style="border:1px solid #000000;"></canvas>Copied!✕CopyIn the JavaScript, you can get a reference to the canvas element and its drawing context, which is an object that provides methods and properties for drawing on the canvas:
var canvas = document.getElementById("myCanvas");var ctx = canvas.getContext("2d");Copied!✕CopyDrawing Shapes
You can draw various shapes on the canvas using the drawing context. For example, to draw a rectangle:
ctx.fillStyle = "green";ctx.fillRect(10, 10, 150, 100);Copied!✕Copy Canvas API - W3Schools
The Canvas API allows JavaScript to draw graphics on the canvas. The Canvas API can draw shapes, lines, curves, boxes, text, and images, with colors, rotations, transparencies, and other pixel …
Canvas API - Web APIs | MDN - MDN Web Docs
- The Canvas API provides a means for drawing graphics via JavaScript and the HTML <canvas> elemen…
The Canvas API largely focuses on 2D graphics. The WebGL API, which also uses the <canvas> element, draws hardware-accelerated 2D and 3D graphics.
Code sample
var canvas = document.getElementById("canvas");var ctx = canvas.getContext("2d");ctx.fillStyle = "green";ctx.fillRect(10, 10, 100, 100);Documentation under CC-BY-SA 2.5 license · Code under CC0 license- The Canvas API provides a means for drawing graphics via JavaScript and the HTML <canvas> elemen…
Canvas (Java Platform SE 8 ) - Oracle
A Canvas component represents a blank rectangular area of the screen onto which the application can draw or from which the application can trap input events from the user. An application must subclass …
JavaScript Canvas
HTML5 features the <canvas> element that allows you to draw 2D graphics using JavaScript. The <canvas> element requires at least two attributes: width and …
How to Draw with JavaScript on an HTML Canvas …
Feb 8, 2024 · There are many ways to code graphics for the web. You can create art with CSS. You can code an SVG image as part of an HTML file. Or you can …
Searches you might like
Web API Canvas - GeeksforGeeks
Jul 23, 2025 · Web API Canvas facilitates the Canvas API to create 2D graphics with an HTML5 element helps developers to draw and control graphics, animations, …
JavaScript Introduction to the Canvas API — xjavascript.com
The Canvas API in JavaScript provides a powerful and flexible way to draw graphics on a web page in real - time. It allows developers to create dynamic and interactive visual content, such as animations, …
JavaScript Canvas: Drawing Graphics with the Canvas API
Aug 27, 2024 · Learn how to use the Canvas API in JavaScript to draw graphics and create dynamic visual content. This guide covers basic to advanced techniques …
Canvas tutorial - Web APIs - MDN
Sep 21, 2025 · This tutorial describes how to use the <canvas> element to draw 2D graphics, starting with the basics. The examples provided should give you some clear ideas about what you can do with …
This guide provided an overview of the HTML5 Canvas and JavaScript integration, covering basic to advanced techniques. By following the code examples, explanations, and completing the exercises, …