WebGL (Web Graphics Library) is a JavaScript API for rendering high-performance interactive 3D and 2D graphics within any compatible web browser without the use of plug-ins. WebGL does so by introducing an API that closely conforms to OpenGL ES 2.0 that can be used in HTML <canvas> elements. This conformance makes it possible for the API to take advantage of hardware graphics acceleration provided by the user's device.
Support for WebGL is present in all modern browsers (see the compatibility tables below); however, the user's device must also have hardware that supports these features.
The WebGL 2 API introduces support for much of the OpenGL ES 3.0 feature set; it's provided through the WebGL2RenderingContext interface.
The <canvas> element is also used by the Canvas API to do 2D graphics on web pages.
WebGL 2 is a major update to WebGL which is provided through the WebGL2RenderingContext interface. It is based on OpenGL ES 3.0 and new features include:
This example demonstrates the simple animation of a one-color shape. Topics examined are adapting to aspect ratio differences, a function to build shader programs from sets of multiple shaders, and the basics of drawing in WebGL.
A series of live samples with short explanations that showcase WebGL concepts and capabilities. The examples are sorted according to topic and level of difficulty, covering the WebGL rendering context, shader programming, textures, geometry, user interaction, and more.
12To access the WebGL context, use experimental-webgl rather than the standard webgl identifier.
4
11To access the WebGL context, use experimental-webgl rather than the standard webgl identifier.
12
5.1
4.4.3
25
4
12
8
1.5
activeTexture
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
attachShader
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
bindAttribLocation
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
bindBuffer
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
bindFramebuffer
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
bindRenderbuffer
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
bindTexture
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
blendColor
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
blendEquation
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
blendEquationSeparate
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
blendFunc
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
blendFuncSeparate
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
bufferData
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
bufferSubData
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
canvas
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
checkFramebufferStatus
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
clear
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
clearColor
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
clearDepth
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
clearStencil
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
colorMask
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
compileShader
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
compressedTexImage2D
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
compressedTexSubImage2D
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
copyTexImage2D
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
copyTexSubImage2D
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
createBuffer
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
createFramebuffer
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
createProgram
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
createRenderbuffer
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
createShader
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
createTexture
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
cullFace
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
deleteBuffer
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
deleteFramebuffer
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
deleteProgram
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
deleteRenderbuffer
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
deleteShader
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
deleteTexture
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
depthFunc
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
depthMask
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
depthRange
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
detachShader
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
disable
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
disableVertexAttribArray
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
drawArrays
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
drawElements
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
drawingBufferColorSpace
104
104
No
No
90
16.4
104
104
No
71
16.4
20.0
drawingBufferHeight
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
drawingBufferWidth
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
enable
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
enableVertexAttribArray
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
finish
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
flush
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
framebufferRenderbuffer
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
framebufferTexture2D
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
frontFace
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
generateMipmap
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
getActiveAttrib
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
getActiveUniform
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
getAttachedShaders
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
getAttribLocation
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
getBufferParameter
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
getContextAttributes
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
getError
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
getExtension
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
getFramebufferAttachmentParameter
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
getParameter
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
getProgramInfoLog
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
getProgramParameter
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
getRenderbufferParameter
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
getShaderInfoLog
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
getShaderParameter
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
getShaderPrecisionFormat
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
getShaderSource
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
getSupportedExtensions
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
getTexParameter
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
getUniform
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
getUniformLocation
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
getVertexAttrib
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
getVertexAttribOffset
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
hint
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
isBuffer
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
isContextLost
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
isEnabled
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
isFramebuffer
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
isProgram
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
isRenderbuffer
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
isShader
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
isTexture
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
lineWidth
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
linkProgram
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
makeXRCompatible
79
79
No
No
No
No
No
79
No
No
No
11.2
pixelStorei
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
polygonOffset
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
readPixels
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
renderbufferStorage
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
sampleCoverage
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
scissor
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
shaderSource
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
stencilFunc
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
stencilFuncSeparate
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
stencilMask
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
stencilMaskSeparate
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
stencilOp
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
stencilOpSeparate
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
texImage2D
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
texParameterf
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
texParameteri
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
texSubImage2D
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
uniform1f
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
uniform1fv
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
uniform1i
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
uniform1iv
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
uniform2f
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
uniform2fv
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
uniform2i
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
uniform2iv
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
uniform3f
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
uniform3fv
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
uniform3i
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
uniform3iv
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
uniform4f
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
uniform4fv
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
uniform4i
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
uniform4iv
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
uniformMatrix2fv
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
uniformMatrix3fv
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
uniformMatrix4fv
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
unpackColorSpace
104
104
No
No
90
No
104
104
No
71
No
20.0
useProgram
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
validateProgram
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
vertexAttrib1f
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
vertexAttrib1fv
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
vertexAttrib2f
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
vertexAttrib2fv
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
vertexAttrib3f
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
vertexAttrib3fv
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
vertexAttrib4f
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
vertexAttrib4fv
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
vertexAttribPointer
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
viewport
9
12
4
11
12
5.1
4.4.3
25
4
12
8
1.5
worker_support
No
No
105
No
No
No
No
No
105
No
No
No
api.WebGLRenderingContext
BCD tables only load in the browser
api.WebGL2RenderingContext
BCD tables only load in the browser
Compatibility notes
In addition to the browser, the GPU itself also needs to support the feature. So, for example, S3 Texture Compression (S3TC) is only available on Tegra-based tablets. Most browsers make the WebGL context available through the webgl context name, but older ones need experimental-webgl as well. In addition, the upcoming WebGL 2 is fully backwards-compatible and will have the context name webgl2.
Gecko notes
WebGL debugging and testing
Firefox provides two preferences available which let you control the capabilities of WebGL for testing purposes:
A Boolean property that, when true, enables a minimum capability mode. When in this mode, WebGL is configured to only support the bare minimum feature set and capabilities required by the WebGL specification. This lets you ensure that your WebGL code will work on any device or browser, regardless of their capabilities. This is false by default.