WebGLRenderingContext: canvas property
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Note: This feature is available inWeb Workers.
TheWebGLRenderingContext.canvas property is a read-onlyreference to theHTMLCanvasElement orOffscreenCanvasobject that is associated with the context. It might benull if it is notassociated with a<canvas> element or anOffscreenCanvasobject.
In this article
Value
Either aHTMLCanvasElement orOffscreenCanvas object ornull.
Examples
>Canvas element
Given this<canvas> element:
html
<canvas></canvas>You can get back a reference to it from theWebGLRenderingContext usingthecanvas property:
js
const canvas = document.getElementById("canvas");const gl = canvas.getContext("webgl");gl.canvas; // HTMLCanvasElementOffscreen canvas
Example using the experimentalOffscreenCanvas object.
js
const offscreen = new OffscreenCanvas(256, 256);const gl = offscreen.getContext("webgl");gl.canvas; // OffscreenCanvasSpecifications
| Specification |
|---|
| WebGL Specification> # DOM-WebGLRenderingContext-canvas> |
Browser compatibility
See also
CanvasRenderingContext2D.canvas- The
OffscreenCanvasinterface