Robots Atlas>ROBOTS ATLAS
Standard

Canvas

2004ActivePublished: 30 November 2026Updated: 30 November 2026Published
Key innovation
Added a programmable, raster (bitmap) drawing surface to HTML, driven from JavaScript in immediate mode โ€” unlike SVG's vector, retained-mode DOM model.
Category
Standard
Abstraction level
Standard
Operation level
ApplicationTooling
Use cases
2D game graphics and animationData visualization and chartsImage manipulation and photo editingReal-time video processing3D rendering via WebGL/WebGPURendering target for AI-generated drawing code

How it works

You place a <canvas> element on the page (optionally with width/height attributes; default 300ร—150). In JavaScript you get a reference to the element (HTMLCanvasElement) and call getContext("2d"), receiving a CanvasRenderingContext2D object. You then issue drawing commands on that context โ€” e.g. fillStyle, fillRect(x, y, w, h), paths (Path2D), text, images โ€” which immediately modify the bitmap (immediate mode). Because the canvas stores only pixels, the application manages scene state itself and redraws every frame (e.g. in a requestAnimationFrame loop). For 3D you use the "webgl"/"webgl2" or "webgpu" context instead of "2d". OffscreenCanvas allows drawing off the main thread (e.g. in a Web Worker).

Problem solved

Early HTML had no native way to draw graphics dynamically and programmatically on the client. Canvas provides a raster surface on which a script can draw pixel by pixel (shapes, text, images, video frames) without plugins such as Flash.

Components

<canvas> element (HTMLCanvasElement)Drawing surface / entry point

The HTML element embedding the bitmap on the page; exposes the getContext() method. Default dimensions 300ร—150 px.

2D context (CanvasRenderingContext2D)2D drawing API

Object returned by getContext("2d"); provides the API to draw shapes, paths, text and images.

Official

getContext()Context selector

Method selecting the drawing context by id: "2d", "bitmaprenderer", "webgl", "webgl2", "webgpu". Returns null for an unsupported or mismatched context.

3D contexts (WebGL / WebGL2 / WebGPU)3D rendering

3D rendering contexts on the same canvas surface; "webgl"/"webgl2" are based on OpenGL ES, "webgpu" is the newer GPU standard.

Official

OffscreenCanvasOff-main-thread drawing

A canvas that runs off the main thread (e.g. in a Web Worker), decoupled from the DOM.

Official

Implementation

Implementation pitfalls
No accessibility or semanticsHigh

Canvas content is not exposed to accessibility tools the way semantic HTML is โ€” it is just a bitmap.

Fix:Treat canvas like an image; provide alternative accessible content (fallback content, ARIA, a parallel DOM).
Blurriness on HiDPI displaysMedium

Canvas pixels do not scale and can become blurry under magnification or on high-density displays.

Fix:Scale the bitmap by window.devicePixelRatio and set the drawing size relative to the CSS size.
No object retention (immediate mode)Medium

Canvas keeps no information about drawn objects; after any change the scene must be redrawn manually.

Fix:Maintain your own scene model and redraw (e.g. in a requestAnimationFrame loop) or use SVG when object addressability is needed.

Evolution

2004
Apple introduces <canvas> in WebKit
Inflection point

Canvas appears in the WebKit component on Mac OS X, powering Dashboard widgets and the Safari browser.

2005
Adopted in Gecko (Firefox)

Mozilla's Gecko engine adds canvas support in version 1.8.

2006
Adopted in Opera

Opera adds canvas support; the element is subsequently standardized by the WHATWG as part of HTML5 / the HTML Living Standard.

Hyperparameters (configurable axes)

Bitmap widthHigh

Bitmap width in pixels. Defaults to 300. Changing it clears the canvas.

300Default per the HTML specification.
Bitmap heightHigh

Bitmap height in pixels. Defaults to 150. Changing it clears the canvas.

150Default per the HTML specification.
Context typeCritical

Context id passed to getContext(): "2d", "bitmaprenderer", "webgl", "webgl2", "webgpu".

2d2D context defined in the HTML specification.
webglOpenGL ES-based 3D context.

Hardware requirements

Good fit

The 2D context runs on any hardware (CPU) and rendering may be GPU-accelerated; the WebGL/WebGPU contexts use the GPU directly.