files/en-us/web/api/htmlcanvaselement/index.md
{{APIRef("Canvas API")}}
The HTMLCanvasElement interface provides properties and methods for manipulating the layout and presentation of {{HtmlElement("canvas")}} elements. The HTMLCanvasElement interface also inherits the properties and methods of the {{domxref("HTMLElement")}} interface.
{{InheritanceDiagram}}
Inherits properties from its parent, {{domxref("HTMLElement")}}.
height HTML attribute of the {{HTMLElement("canvas")}} element is a non-negative integer reflecting the number of logical pixels (or RGBA values) going down one column of the canvas. When the attribute is not specified, or if it is set to an invalid value, like a negative, the default value of 150 is used. If no [separate] CSS height is assigned to the {{HTMLElement("canvas")}}, then this value will also be used as the height of the canvas in the length-unit CSS Pixel.width HTML attribute of the {{HTMLElement("canvas")}} element is a non-negative integer reflecting the number of logical pixels (or RGBA values) going across one row of the canvas. When the attribute is not specified, or if it is set to an invalid value, like a negative, the default value of 300 is used. If no [separate] CSS width is assigned to the {{HTMLElement("canvas")}}, then this value will also be used as the width of the canvas in the length-unit CSS Pixel.moz-opaque HTML attribute of the {{HTMLElement("canvas")}} element. It lets the canvas know whether or not translucency will be a factor. If the canvas knows there's no translucency, painting performance can be optimized. This is only supported in Mozilla-based browsers; use the standardized {{domxref("HTMLCanvasElement.getContext()", "canvas.getContext('2d', { alpha: false })")}} instead.function that is Initially null. Web content can set this to a JavaScript function that will be called when the canvas is to be redrawn while the page is being printed. When called, the callback is passed a "printState" object that implements the MozCanvasPrintState interface. The callback can get the context to draw to from the printState object and must then call done() on it when finished. The purpose of mozPrintCallback is to obtain a higher resolution rendering of the canvas at the resolution of the printer being used. See this blog post.Inherits methods from its parent, {{domxref("HTMLElement")}}.
null if the context identifier is not supported, or the canvas has already been set to a different context mode.type parameter (defaults to png). The returned image is in a resolution of 96dpi.Inherits events from its parent, {{domxref("HTMLElement")}}.
Listen to these events using {{DOMxRef("EventTarget.addEventListener", "addEventListener()")}} or by assigning an event listener to the oneventname property of this interface.
contextlost
CanvasRenderingContext2D context has been lost.contextrestored
CanvasRenderingContext2D contextwebglcontextcreationerror
WebGLRenderingContext or WebGL2RenderingContext context.webglcontextlost
WebGLRenderingContext or WebGL2RenderingContext object has been lost.webglcontextrestored
WebGLRenderingContext or WebGL2RenderingContext object.{{Specifications}}
{{Compat}}