Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 697139 of CanvasRenderingContext2D

  • Revision slug: Web/API/CanvasRenderingContext2D
  • Revision title: CanvasRenderingContext2D
  • Revision id: 697139
  • Created:
  • Creator: fscholz
  • Is current revision? No
  • Comment

Revision Content

{{APIRef}}
The CanvasRenderingContext2D interface provides the 2D rendering context for the drawing surface of a {{ HTMLElement("canvas") }} element.

To get an object of this interface, call {{domxref("HTMLCanvasElement.getContext()", "getContext()")}} on a <canvas>, supplying "2d" as the argument:

var canvas = document.getElementById('mycanvas');
var ctx = canvas.getContext('2d');

Once you have the 2D rendering context for a canvas, you can draw within it. For example:

ctx.fillStyle = "rgb(200,0,0)";  
ctx.fillRect(10, 10, 55, 50);  

See the properties and methods in the sidebar and below. The canvas tutorial has more information, examples, and resources as well.

Drawing rectangles

There are three methods that immediately draw rectangles to the bitmap.

{{domxref("CanvasRenderingContext2D.clearRect()")}}
Sets all pixels in the rectangle defined by starting point (x, y) and size (width, height) to transparent black, erasing any previously drawn content.
{{domxref("CanvasRenderingContext2D.fillRect()")}}
Draws a filled rectangle at (x, y) position whose size is determined by width and height.
{{domxref("CanvasRenderingContext2D.strokeRect()")}}
Paints a rectangle which has a starting point at (x, y) and has a w width and an h height onto the canvas, using the current stroke style.

Drawing text

The following methods are provided for drawing text. See also the {{domxref("TextMetrics")}} object for text properties.

{{domxref("CanvasRenderingContext2D.fillText()")}}
Draws (fills) a given text at the given (x,y) position.
{{domxref("CanvasRenderingContext2D.strokeText()")}}
Draws (strokes) a given text at the given (x, y) position.
{{domxref("CanvasRenderingContext2D.measureText()")}}
Returns a {{domxref("TextMetrics")}} object.

Line styles

The following methods and properties control how lines are drawn.

{{domxref("CanvasRenderingContext2D.lineWidth")}}
Width of lines. Default 1.0
{{domxref("CanvasRenderingContext2D.lineCap")}}
Type of endings on the end of lines. Possible values: butt (default), round, square.
{{domxref("CanvasRenderingContext2D.lineJoin")}}
Defines the type of corners where two lines meet. Possible values: round, bevel, miter (default).
{{domxref("CanvasRenderingContext2D.miterLimit")}}
Miter limit ratio. Default 10.
{{domxref("CanvasRenderingContext2D.getLineDash()")}}
Returns the current line dash pattern array containing an even number of non-negative numbers.
{{domxref("CanvasRenderingContext2D.setLineDash()")}}
Sets the current line dash pattern.
{{domxref("CanvasRenderingContext2D.lineDashOffset")}}
Specifies where to start a dash array on a line.

Text styles

The following properties control how text is laid out.

{{domxref("CanvasRenderingContext2D.font")}}
Font setting. Default value 10px sans-serif.
{{domxref("CanvasRenderingContext2D.textAlign")}}
Text alignment setting. Possible values: start (default), end, left, right or center.
{{domxref("CanvasRenderingContext2D.textBaseline")}}
Baseline alignment setting. Possible values: top, hanging, middle, alphabetic (default), ideographic, bottom.
{{domxref("CanvasRenderingContext2D.direction")}}
Directionality. Possible values: ltr, rtl, inherit (default).

Fill and stroke styles

Fill styling is used for colors and styles inside shapes and stroke styling is used for the lines around shapes.

{{domxref("CanvasRenderingContext2D.fillStyle")}}
Color or style to use inside shapes. Default #000 (black).
{{domxref("CanvasRenderingContext2D.strokeStyle")}}
Color or style to use for the lines around shapes. Default #000 (black).

Gradients and patterns

{{domxref("CanvasRenderingContext2D.createLinearGradient()")}}
Creates a linear gradient along the line given by the coordinates represented by the parameters.
{{domxref("CanvasRenderingContext2D.createRadialGradient()")}}
Creates a radial gradient along the line given by the coordinates represented by the parameters.
{{domxref("CanvasRenderingContext2D.createPattern()")}}
Creates a pattern using the specified image (a {{domxref("CanvasImageSource")}}). It repeats the source in the directions specified by the repetition argument. This method returns a {{domxref("CanvasPattern")}}.

Shadows

{{domxref("CanvasRenderingContext2D.shadowBlur")}}
Specifies the blurring effect. Default 0
{{domxref("CanvasRenderingContext2D.shadowColor")}}
Color of the shadow. Default fully-transparent black.
{{domxref("CanvasRenderingContext2D.shadowOffsetX")}}
Horizontal distance the shadow will be offset. Default 0.
{{domxref("CanvasRenderingContext2D.shadowOffsetY")}}
Vertical distance the shadow will be offset. Default 0.

Paths

The following methods can be used to manipulate paths of objects.

{{domxref("CanvasRenderingContext2D.beginPath()")}}
Starts a new path by emptying the list of sub-paths. Call this method when you want to create a new path.
{{domxref("CanvasRenderingContext2D.closePath()")}}
Causes the point of the pen to move back to the start of the current sub-path. It tries to draw a straight line from the current point to the start. If the shape has already been closed or has only one point, this function does nothing.
{{domxref("CanvasRenderingContext2D.moveTo()")}}
Moves the starting point of a new sub-path to the (x, y) coordinates.
{{domxref("CanvasRenderingContext2D.lineTo()")}}
Connects the last point in the subpath to the x, y coordinates with a straight line.
{{domxref("CanvasRenderingContext2D.bezierCurveTo()")}}
Adds a cubic Bézier curve to the path. It requires three points. The first two points are control points and the third one is the end point. The starting point is the last point in the current path, which can be changed using moveTo() before creating the Bézier curve.
{{domxref("CanvasRenderingContext2D.quadraticCurveTo()")}}
Adds a quadratic Bézier curve to the current path.
{{domxref("CanvasRenderingContext2D.arc()")}}
Adds an arc to the path which is centered at (x, y) position with radius r starting at startAngle and ending at endAngle going in the given direction by anticlockwise (defaulting to clockwise).
{{domxref("CanvasRenderingContext2D.arcTo()")}}
Adds an arc to the path with the given control points and radius, connected to the previous point by a straight line.
{{domxref("CanvasRenderingContext2D.ellipse()")}} {{experimental_inline}}
Adds an ellipse to the path which is centered at (x, y) position with the radii radiusX and radiusY starting at startAngle and ending at endAngle going in the given direction by anticlockwise (defaulting to clockwise).
{{domxref("CanvasRenderingContext2D.rect()")}}
Creates a path for a rectangle at position (x, y) with a size that is determined by width and height.

Drawing paths

{{domxref("CanvasRenderingContext2D.fill()")}}
Fills the subpaths with the current fill style.
{{domxref("CanvasRenderingContext2D.stroke()")}}
Strokes the subpaths with the current stroke style.
{{domxref("CanvasRenderingContext2D.drawCustomFocusRing()")}}
tbd
{{domxref("CanvasRenderingContext2D.drawSystemFocusRing()")}}
tbd
{{domxref("CanvasRenderingContext2D.drawFocusIfNeeded()")}}
tbd
{{domxref("CanvasRenderingContext2D.scrollPathIntoView()")}}
tbd
{{domxref("CanvasRenderingContext2D.clip()")}}
Creates a clipping path from the current sub-paths. Everything drawn after clip() is called appears inside the clipping path only. For an example, see Clipping paths in the Canvas tutorial.
{{domxref("CanvasRenderingContext2D.isPointInPath()")}}
Reports whether or not the specified point is contained in the current path.
{{domxref("CanvasRenderingContext2D.isPointInStroke()")}}
Reports whether or not the specified point is inside the area contained by the stroking of a path.

Transformations

Objects in the CanvasRenderingContext2D rendering context have a current transformation matrix and methods to manipulate it. The transformation matrix is applied when creating the current default path, painting text, shapes and {{domxref("Path2D")}} objects. The methods listed below remain for historical and compatibility reasons as {{domxref("SVGMatrix")}} objects are used in most parts of the API nowadays and will be used in the future instead.

{{domxref("CanvasRenderingContext2D.currentTransform")}}
Current transformation matrix ({{domxref("SVGMatrix")}} object).
{{domxref("CanvasRenderingContext2D.rotate()")}}
Adds a rotation to the transformation matrix. The angle argument represents a clockwise rotation angle and is expressed in radians.
{{domxref("CanvasRenderingContext2D.scale()")}}
Adds a scaling transformation to the canvas units by x horizontally and by y vertically.
{{domxref("CanvasRenderingContext2D.translate()")}}
Adds a translation transformation by moving the canvas and its origin x horzontally and y vertically on the grid.
{{domxref("CanvasRenderingContext2D.transform()")}}
Multiplies the current transformation matrix with the matrix described by its arguments.
{{domxref("CanvasRenderingContext2D.setTransform()")}}
Resets the current transform to the identity matrix, and then invokes the transform() method with the same arguments.
{{domxref("CanvasRenderingContext2D.resetTransform()")}} {{experimental_inline}}
Resets the current transform by the identity matrix.

Compositing

{{domxref("CanvasRenderingContext2D.globalAlpha")}}
Alpha value that is applied to shapes and images before they are composited onto the canvas. Default 1.0 (opaque).
{{domxref("CanvasRenderingContext2D.globalCompositeOperation")}}
With globalAlpha applied this sets how shapes and images are drawn onto the existing bitmap.

Drawing images

{{domxref("CanvasRenderingContext2D.drawImage()")}}
Draws the specified image. This method is available in multiple formats, providing a great deal of flexibility in its use.

Pixel manipulation

See also the {{domxref("ImageData")}} object.

{{domxref("CanvasRenderingContext2D.createImageData()")}}
Creates a new, blank {{domxref("ImageData")}} object with the specified dimensions. All of the pixels in the new object are transparent black.
{{domxref("CanvasRenderingContext2D.getImageData()")}}
Returns an {{domxref("ImageData")}} object representing the underlying pixel data for the area of the canvas denoted by the rectangle which starts at (sx, sy) and has an sw width and sh height.
{{domxref("CanvasRenderingContext2D.putImageData()")}}
Paints data from the given {{domxref("ImageData")}} object onto the bitmap. If a dirty rectangle is provided, only the pixels from that rectangle are painted.

Image smoothing

{{domxref("CanvasRenderingContext2D.imageSmoothingEnabled")}} {{experimental_inline}}
Image smoothing mode; if disabled, images will not be smoothed if scaled.

The canvas state

The CanvasRenderingContext2D rendering context contains a variety of drawing style states (attributes for line styles, fill styles, shadow styles, text styles). The following methods help you to work with that state:

{{domxref("CanvasRenderingContext2D.save()")}}
Saves the current drawing style state using a stack so you can revert any change you make to it using restore().
{{domxref("CanvasRenderingContext2D.restore()")}}
Restores the drawing style state to the last element on the 'state stack' saved by save().
{{domxref("CanvasRenderingContext2D.canvas")}}
A read-only back-reference to the {{domxref("HTMLCanvasElement")}}. Might be {{jsxref("null")}} if it is not associated with a {{HTMLElement("canvas")}} element.

Hit regions

{{domxref("CanvasRenderingContext2D.addHitRegion()")}}
tbd
{{domxref("CanvasRenderingContext2D.removeHitRegion()")}}
tbd
{{domxref("CanvasRenderingContext2D.clearHitRegions()")}}
tbd

Non-standard APIs

Most of these APIs are deprecated and will be removed in the future.

{{non-standard_inline}} CanvasRenderingContext2D.clearShadow()
Removes all shadow settings like {{domxref("CanvasRenderingContext2D.shadowColor")}} and {{domxref("CanvasRenderingContext2D.shadowBlur")}}.
{{non-standard_inline}} CanvasRenderingContext2D.drawImageFromRect()
This is redundant with an equivalent overload of drawImage.
{{non-standard_inline}} CanvasRenderingContext2D.setAlpha()
Use {{domxref("CanvasRenderingContext2D.globalAlpha")}} instead.
{{non-standard_inline}} CanvasRenderingContext2D.setCompositeOperation()
Use {{domxref("CanvasRenderingContext2D.globalCompositeOperation")}} instead.
{{non-standard_inline}} CanvasRenderingContext2D.setLineWidth()
Use {{domxref("CanvasRenderingContext2D.lineWidth")}} instead.
{{non-standard_inline}} CanvasRenderingContext2D.setLineJoin()
Use {{domxref("CanvasRenderingContext2D.lineJoin")}} instead.
{{non-standard_inline}} CanvasRenderingContext2D.setLineCap()
Use {{domxref("CanvasRenderingContext2D.lineCap")}} instead.
{{non-standard_inline}} CanvasRenderingContext2D.setMiterLimit()
Use {{domxref("CanvasRenderingContext2D.miterLimit")}} instead.
{{non-standard_inline}} CanvasRenderingContext2D.setStrokeColor()
Use {{domxref("CanvasRenderingContext2D.strokeStyle")}} instead.
{{non-standard_inline}} CanvasRenderingContext2D.setFillColor()
Use {{domxref("CanvasRenderingContext2D.fillStyle")}} instead.
{{non-standard_inline}} CanvasRenderingContext2D.setShadow()
Use {{domxref("CanvasRenderingContext2D.shadowColor")}} and {{domxref("CanvasRenderingContext2D.shadowBlur")}} instead.
{{non-standard_inline}} CanvasRenderingContext2D.webkitLineDash
Use {{domxref("CanvasRenderingContext2D.getLineDash()")}} and {{domxref("CanvasRenderingContext2D.setLineDash()")}} instead.
{{non-standard_inline}} CanvasRenderingContext2D.webkitLineDashOffset
Use {{domxref("CanvasRenderingContext2D.lineDashOffset")}} instead.
{{non-standard_inline}} CanvasRenderingContext2D.webkitImageSmoothingEnabled
Use {{domxref("CanvasRenderingContext2D.imageSmoothingEnabled")}} instead.
{{non-standard_inline}} CanvasRenderingContext2D.getContextAttributes()
Inspired by the same WebGLRenderingContext method it returns an Canvas2DContextAttributes object that contains the attributes "storage" to indicate which storage is used ("persistent" by default) and the attribute "alpha" (true by default) to indicate that transparency is used in the canvas.
{{non-standard_inline}} CanvasRenderingContext2D.isContextLost()
Inspired by the same WebGLRenderingContext method it returns true if the Canvas context has been lost, or false if not.

WebKit only

{{non-standard_inline}} CanvasRenderingContext2D.webkitBackingStorePixelRatio
The backing store size in relation to the canvas element. See High DPI Canvas.
{{non-standard_inline}} CanvasRenderingContext2D.webkitGetImageDataHD
Intended for HD backing stores, but removed from canvas specifications.
{{non-standard_inline}} CanvasRenderingContext2D.webkitPutImageDataHD
Intended for HD backing stores, but removed from canvas specifications.

Gecko only

{{non-standard_inline}} {{domxref("CanvasRenderingContext2D.filter")}}
CSS and SVG filters as Canvas APIs. Likely to be standardized in a new version of the specification.

Prefixed APIs

{{non-standard_inline}} CanvasRenderingContext2D.mozCurrentTransform
Sets or gets the current transformation matrix, see {{domxref("CanvasRenderingContext2D.currentTransform")}}.  {{ gecko_minversion_inline("7.0") }}
{{non-standard_inline}} CanvasRenderingContext2D.mozCurrentTransformInverse
Sets or gets the current inversed transformation matrix.  {{ gecko_minversion_inline("7.0") }}
{{non-standard_inline}} CanvasRenderingContext2D.mozFillRule
The fill rule to use. This must be one of evenodd or nonzero (default).
{{non-standard_inline}} CanvasRenderingContext2D.mozImageSmoothingEnabled
See {{domxref("CanvasRenderingContext2D.imageSmoothingEnabled")}}.
{{non-standard_inline}} {{deprecated_inline}} CanvasRenderingContext2D.mozDash
An array which specifies the lengths of alternating dashes and gaps {{ gecko_minversion_inline("7.0") }}. Use {{domxref("CanvasRenderingContext2D.getLineDash()")}} and {{domxref("CanvasRenderingContext2D.setLineDash()")}} instead.
{{non-standard_inline}} {{deprecated_inline}} CanvasRenderingContext2D.mozDashOffset
Specifies where to start a dash array on a line. {{ gecko_minversion_inline("7.0") }}. Use {{domxref("CanvasRenderingContext2D.lineDashOffset")}} instead.
{{non-standard_inline}} {{deprecated_inline}} CanvasRenderingContext2D.mozTextStyle
Introduced in in Gecko 1.9, deprecated in favor of the {{domxref("CanvasRenderingContext2D.font")}} property.
{{non-standard_inline}} {{obsolete_inline}} CanvasRenderingContext2D.mozDrawText()
This method was introduced in Gecko 1.9 and is removed starting with Gecko 7.0. Use {{domxref("CanvasRenderingContext2D.strokeText()")}} or {{domxref("CanvasRenderingContext2D.fillText()")}} instead.
{{non-standard_inline}} {{obsolete_inline}} CanvasRenderingContext2D.mozMeasureText()
This method was introduced in Gecko 1.9 and is unimplemented starting with Gecko 7.0. Use {{domxref("CanvasRenderingContext2D.measureText()")}} instead.
{{non-standard_inline}} {{obsolete_inline}} CanvasRenderingContext2D.mozPathText()
This method was introduced in Gecko 1.9 and is removed starting with Gecko 7.0.
{{non-standard_inline}} {{obsolete_inline}} CanvasRenderingContext2D.mozTextAlongPath()
This method was introduced in Gecko 1.9 and is removed starting with Gecko 7.0.

Internal APIs (chrome-context only)

{{non-standard_inline}} {{domxref("CanvasRenderingContext2D.asyncDrawXULElement()")}}
Renders a region of a XUL element into the canvas.
{{non-standard_inline}} {{domxref("CanvasRenderingContext2D.drawWindow()")}}
Renders a region of a window into the canvas. The contents of the window's viewport are rendered, ignoring viewport clipping and scrolling.
{{non-standard_inline}} CanvasRenderingContext2D.demote()
This causes a context that is currently using a hardware-accelerated backend to fallback to a software one. All state should be preserved.

Internet Explorer

{{non-standard_inline}} CanvasRenderingContext2D.msFillRule
The fill rule to use. This must be one of evenodd or nonzero (default).

Specifications

Specification Status Comment
{{SpecName('HTML WHATWG', "scripting.html#2dcontext:canvasrenderingcontext2d", "CanvasRenderingContext2D")}} {{Spec2('HTML WHATWG')}}  

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{CompatChrome("1")}} {{CompatGeckoDesktop("1.8")}} {{CompatIE("9")}} {{CompatOpera("9")}} {{CompatSafari("2")}}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

See also

  • {{domxref("HTMLCanvasElement")}}

 

 

WIP

------------------------------------------------------------------------------------------------------------------------------------------

Migrate the following into new subpages:

------------------------------------------------------------------------------------------------------------------------------------------

Note: Starting in {{Gecko("5.0")}}, the following corrections were made to various behaviors in order to improve compliance with the HTML5 specification:

  • getImageData() now correctly accepts rectangles that extend beyond the bounds of the canvas; pixels outside the canvas are returned as transparent black.
  • drawImage() and createImageData() now handle negative arguments in accordance with the specification, by flipping the rectangle around the appropriate axis.
  • Specifying non-finite values when calling createImageData() now properly throws a NOT_SUPPORTED_ERR exception.
  • createImageData() and getImageData() now correctly return at least one pixel's worth of image data if a rectangle smaller than one pixel is specified.
  • Specifying a negative radius when calling createRadialGradient() now correctly throws INDEX_SIZE_ERR.
  • Specifying a null or undefined image when calling createPattern() or drawImage() now correctly throws a TYPE_MISMATCH_ERR exception.
  • Specifying invalid values for globalAlpha no longer throws a SYNTAX_ERR exception; these are now correctly silently ignored.
  • Specifying invalid values when calling translate(), transform(), rect(), clearRect(), fillRect(), strokeRect(), lineTo(), moveTo(), quadraticCurveTo(), or arc() no longer throws an exception; these calls are now correctly silently ignored.
  • Setting the value of shadowOffsetX, shadowOffsetY, or shadowBlur to an invalid value is now silently ignored.
  • Setting the value of rotate or scale to an invalid value is now silently ignored.

 

Revision Source

<div>
 {{APIRef}}</div>
<div class="summary">
 The <code><strong>CanvasRenderingContext2D</strong></code> interface provides the 2D rendering context for the drawing surface of a {{ HTMLElement("canvas") }} element.</div>
<p>To get an object of this interface, call {{domxref("HTMLCanvasElement.getContext()", "getContext()")}} on a <code>&lt;canvas&gt;</code>, supplying "2d" as the argument:</p>
<pre class="brush: js">
var canvas = document.getElementById('mycanvas');
var ctx = canvas.getContext('2d');
</pre>
<p>Once you have the 2D rendering context for a canvas, you can draw within it. For example:</p>
<pre class="brush: js">
ctx.fillStyle = "rgb(200,0,0)";  
ctx.fillRect(10, 10, 55, 50);  
</pre>
<p>See the properties and methods in the sidebar and below. The <a href="/en-US/docs/Web/API/Canvas_API/Tutorial" title="Canvas tutorial">canvas tutorial</a> has more information, examples, and resources as well.</p>
<h2 id="Drawing_rectangles">Drawing rectangles</h2>
<p>There are three methods that immediately draw rectangles to the bitmap.</p>
<dl>
 <dt>
  {{domxref("CanvasRenderingContext2D.clearRect()")}}</dt>
 <dd>
  Sets all pixels in the rectangle defined by starting point&nbsp;<em>(x, y)</em>&nbsp;and size <em>(width, height)</em>&nbsp;to transparent black, erasing any previously drawn content.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.fillRect()")}}</dt>
 <dd>
  Draws a filled rectangle at <em>(x, y) </em>position whose size is determined by <em>width</em> and <em>height</em>.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.strokeRect()")}}</dt>
 <dd>
  Paints a rectangle which has a starting point at <em>(x, y)</em> and has a<em> w</em> width and an <em>h</em> height onto the canvas, using the current stroke style.</dd>
</dl>
<h2 id="Drawing_text">Drawing text</h2>
<p>The following methods are provided for drawing text. See also the {{domxref("TextMetrics")}} object for text properties.</p>
<dl>
 <dt>
  {{domxref("CanvasRenderingContext2D.fillText()")}}</dt>
 <dd>
  Draws (fills) a given text at the given (x,y) position.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.strokeText()")}}</dt>
 <dd>
  Draws (strokes) a given text at the given <em>(x, y) </em>position.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.measureText()")}}</dt>
 <dd>
  Returns a {{domxref("TextMetrics")}} object.</dd>
</dl>
<h2 id="Line_styles">Line styles</h2>
<p>The following methods and properties control how lines are drawn.</p>
<dl>
 <dt>
  {{domxref("CanvasRenderingContext2D.lineWidth")}}</dt>
 <dd>
  Width of lines. Default <code>1.0</code></dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.lineCap")}}</dt>
 <dd>
  Type of endings on the end of lines. Possible values: <code>butt</code> (default), <code>round</code>, <code>square</code>.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.lineJoin")}}</dt>
 <dd>
  Defines the type of corners where two lines meet. Possible values: <code>round</code>, <code>bevel</code>, <code>miter</code> (default).</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.miterLimit")}}</dt>
 <dd>
  Miter limit ratio. Default <code>10</code>.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.getLineDash()")}}</dt>
 <dd>
  Returns the current line dash pattern array containing an even number of non-negative numbers.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.setLineDash()")}}</dt>
 <dd>
  Sets the current line dash pattern.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.lineDashOffset")}}</dt>
 <dd>
  Specifies where to start a dash array on a line.</dd>
</dl>
<h2 id="Text_styles">Text styles</h2>
<p>The following properties control how text is laid out.</p>
<dl>
 <dt>
  {{domxref("CanvasRenderingContext2D.font")}}</dt>
 <dd>
  Font setting. Default value <code>10px sans-serif</code>.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.textAlign")}}</dt>
 <dd>
  Text alignment setting. Possible values: <code>start</code> (default), <code>end</code>, <code>left</code>, <code>right</code> or <code>center</code>.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.textBaseline")}}</dt>
 <dd>
  Baseline alignment setting. Possible values: <code>top</code>, <code>hanging</code>, <code>middle</code>, <code>alphabetic</code> (default), <code>ideographic</code>, <code>bottom</code>.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.direction")}}</dt>
 <dd>
  Directionality. Possible values: <code>ltr, rtl</code>, <code>inherit</code> (default).</dd>
</dl>
<h2 id="Fill_and_stroke_styles">Fill and stroke styles</h2>
<p>Fill styling is used for colors and styles inside shapes and stroke styling is used for the lines around shapes.</p>
<dl>
 <dt>
  {{domxref("CanvasRenderingContext2D.fillStyle")}}</dt>
 <dd>
  Color or style to use inside shapes. Default <code>#000</code> (black).</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.strokeStyle")}}</dt>
 <dd>
  Color or style to use for the lines around shapes. Default <code>#000</code> (black).</dd>
</dl>
<h2 id="Gradients_and_patterns">Gradients and patterns</h2>
<dl>
 <dt>
  {{domxref("CanvasRenderingContext2D.createLinearGradient()")}}</dt>
 <dd>
  Creates a linear gradient along the line given by the coordinates represented by the parameters.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.createRadialGradient()")}}</dt>
 <dd>
  Creates a radial gradient along the line given by the coordinates represented by the parameters.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.createPattern()")}}</dt>
 <dd>
  Creates a pattern using the specified image (a {{domxref("CanvasImageSource")}}). It repeats the source in the directions specified by the repetition argument. This method returns a {{domxref("CanvasPattern")}}.</dd>
</dl>
<h2 id="Shadows">Shadows</h2>
<dl>
 <dt>
  {{domxref("CanvasRenderingContext2D.shadowBlur")}}</dt>
 <dd>
  Specifies the blurring effect. Default <code>0</code></dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.shadowColor")}}</dt>
 <dd>
  Color of the shadow. Default fully-transparent black.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.shadowOffsetX")}}</dt>
 <dd>
  Horizontal distance the shadow will be offset. Default 0.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.shadowOffsetY")}}</dt>
 <dd>
  Vertical distance the shadow will be offset. Default 0.</dd>
</dl>
<h2 id="Paths">Paths</h2>
<p>The following methods can be used to manipulate paths of objects.</p>
<dl>
 <dt>
  {{domxref("CanvasRenderingContext2D.beginPath()")}}</dt>
 <dd>
  Starts a new path by emptying the list of sub-paths. Call this method when you want to create a new path.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.closePath()")}}</dt>
 <dd>
  Causes the point of the pen to move back to the start of the current sub-path. It tries to draw a straight line from the current point to the start. If the shape has already been closed or has only one point, this function does nothing.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.moveTo()")}}</dt>
 <dd>
  Moves the starting point of a new sub-path to the <strong>(x, y)</strong> coordinates.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.lineTo()")}}</dt>
 <dd>
  Connects the last point in the subpath to the <code>x, y</code> coordinates with a straight line.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.bezierCurveTo()")}}</dt>
 <dd>
  Adds a cubic Bézier curve to the path. It requires three points. The first two points are control points and the third one is the end point. The starting point is the last point in the current path, which can be changed using <code>moveTo()</code> before creating the Bézier curve.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.quadraticCurveTo()")}}</dt>
 <dd>
  Adds a quadratic Bézier curve to the current path.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.arc()")}}</dt>
 <dd>
  Adds an arc to the path which is centered at <em>(x, y)</em> position with radius<em> r</em> starting at <em>startAngle</em> and ending at <em>endAngle</em> going in the given direction by <em>anticlockwise</em> (defaulting to clockwise).</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.arcTo()")}}</dt>
 <dd>
  Adds an arc to the path with the given control points and radius, connected to the previous point by a straight line.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.ellipse()")}} {{experimental_inline}}</dt>
 <dd>
  Adds an ellipse to the path which is centered at <em>(x, y)</em> position with the radii <em>radiusX</em> and <em>radiusY</em> starting at <em>startAngle</em> and ending at <em>endAngle</em> going in the given direction by <em>anticlockwise</em> (defaulting to clockwise).</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.rect()")}}</dt>
 <dd>
  Creates a path for a rectangle at<em> </em>position <em>(x, y)</em> with a size that is determined by <em>width</em> and <em>height</em>.</dd>
</dl>
<h2 id="Drawing_paths">Drawing paths</h2>
<dl>
 <dt>
  {{domxref("CanvasRenderingContext2D.fill()")}}</dt>
 <dd>
  Fills the subpaths with the current fill style.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.stroke()")}}</dt>
 <dd>
  Strokes the subpaths with the current stroke style.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.drawCustomFocusRing()")}}</dt>
 <dd>
  tbd</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.drawSystemFocusRing()")}}</dt>
 <dd>
  tbd</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.drawFocusIfNeeded()")}}</dt>
 <dd>
  tbd</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.scrollPathIntoView()")}}</dt>
 <dd>
  tbd</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.clip()")}}</dt>
 <dd>
  Creates a clipping path from the current sub-paths. Everything drawn after <code>clip()</code> is called appears inside the clipping path only. For an example, see <a href="/en-US/docs/Web/API/Canvas_API/Tutorial/Compositing" title="Clipping paths">Clipping paths</a> in the Canvas tutorial.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.isPointInPath()")}}</dt>
 <dd>
  Reports whether or not the specified point is contained in the current path.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.isPointInStroke()")}}</dt>
 <dd>
  Reports whether or not the specified point is inside the area contained by the stroking of a path.</dd>
</dl>
<h2 id="Transformations">Transformations</h2>
<p>Objects in the <code>CanvasRenderingContext2D</code> rendering context have a current transformation matrix and methods to manipulate it. The transformation matrix is applied when creating the current default path, painting text, shapes and {{domxref("Path2D")}} objects. The methods listed below remain for historical and compatibility reasons as {{domxref("SVGMatrix")}} objects are used in most parts of the API nowadays and will be used in the future instead.</p>
<dl>
 <dt>
  {{domxref("CanvasRenderingContext2D.currentTransform")}}</dt>
 <dd>
  Current transformation matrix ({{domxref("SVGMatrix")}} object).</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.rotate()")}}</dt>
 <dd>
  Adds a rotation to the transformation matrix. The angle argument represents a clockwise rotation angle and is expressed in radians.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.scale()")}}</dt>
 <dd>
  Adds a scaling transformation to the canvas units by x horizontally and by y vertically.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.translate()")}}</dt>
 <dd>
  Adds a translation transformation by moving the canvas and its origin x horzontally and y vertically on the grid.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.transform()")}}</dt>
 <dd>
  Multiplies the current transformation matrix with the matrix described by its arguments.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.setTransform()")}}</dt>
 <dd>
  Resets the current transform to the identity matrix, and then invokes the <code>transform()</code> method with the same arguments.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.resetTransform()")}} {{experimental_inline}}</dt>
 <dd>
  Resets the current transform by the identity matrix.</dd>
</dl>
<h2 id="Compositing">Compositing</h2>
<dl>
 <dt>
  {{domxref("CanvasRenderingContext2D.globalAlpha")}}</dt>
 <dd>
  Alpha value that is applied to shapes and images before they are composited onto the canvas. Default <code>1.0</code> (opaque).</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.globalCompositeOperation")}}</dt>
 <dd>
  With <code>globalAlpha</code> applied this sets how shapes and images are drawn onto the existing bitmap.</dd>
</dl>
<h2 id="Drawing_images">Drawing images</h2>
<dl>
 <dt>
  {{domxref("CanvasRenderingContext2D.drawImage()")}}</dt>
 <dd>
  Draws the specified image. This method is available in multiple formats, providing a great deal of flexibility in its use.</dd>
</dl>
<h2 id="Pixel_manipulation">Pixel manipulation</h2>
<p>See also the {{domxref("ImageData")}} object.</p>
<dl>
 <dt>
  {{domxref("CanvasRenderingContext2D.createImageData()")}}</dt>
 <dd>
  Creates a new, blank {{domxref("ImageData")}} object with the specified dimensions. All of the pixels in the new object are transparent black.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.getImageData()")}}</dt>
 <dd>
  Returns an {{domxref("ImageData")}} object representing the underlying pixel data for the area of the canvas denoted by the rectangle which starts at <em>(sx, sy)</em> and has an <em>sw</em> width and <em>sh</em> height.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.putImageData()")}}</dt>
 <dd>
  Paints data from the given {{domxref("ImageData")}} object onto the bitmap. If a dirty rectangle is provided, only the pixels from that rectangle are painted.</dd>
</dl>
<h2 id="Image_smoothing">Image smoothing</h2>
<dl>
 <dt>
  {{domxref("CanvasRenderingContext2D.imageSmoothingEnabled")}} {{experimental_inline}}</dt>
 <dd>
  Image smoothing mode; if disabled, images will not be smoothed if scaled.</dd>
</dl>
<h2 id="The_canvas_state">The canvas state</h2>
<p>The <code>CanvasRenderingContext2D</code> rendering context contains a variety of drawing style states (attributes for line styles, fill styles, shadow styles, text styles). The following methods help you to work with that state:</p>
<dl>
 <dt>
  {{domxref("CanvasRenderingContext2D.save()")}}</dt>
 <dd>
  Saves the current drawing style state using a stack so you can revert any change you make to it using <code>restore()</code>.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.restore()")}}</dt>
 <dd>
  Restores the drawing style state to the last element on the 'state stack' saved by <code>save()</code>.</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.canvas")}}</dt>
 <dd>
  A read-only back-reference to the {{domxref("HTMLCanvasElement")}}. Might be {{jsxref("null")}} if it is not associated with a {{HTMLElement("canvas")}} element.</dd>
</dl>
<h2 id="Hit_regions">Hit regions</h2>
<dl>
 <dt>
  {{domxref("CanvasRenderingContext2D.addHitRegion()")}}</dt>
 <dd>
  tbd</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.removeHitRegion()")}}</dt>
 <dd>
  tbd</dd>
 <dt>
  {{domxref("CanvasRenderingContext2D.clearHitRegions()")}}</dt>
 <dd>
  tbd</dd>
</dl>
<h2 id="Non-standard_APIs">Non-standard APIs</h2>
<h3 id="Blink_and_WebKit">Blink and WebKit</h3>
<p>Most of these APIs are <a href="https://code.google.com/p/chromium/issues/detail?id=363198">deprecated and will be removed in the future</a>.</p>
<dl>
 <dt>
  {{non-standard_inline}} <code>CanvasRenderingContext2D.clearShadow()</code></dt>
 <dd>
  Removes all shadow settings like {{domxref("CanvasRenderingContext2D.shadowColor")}} and {{domxref("CanvasRenderingContext2D.shadowBlur")}}.</dd>
 <dt>
  {{non-standard_inline}} <code>CanvasRenderingContext2D.drawImageFromRect()</code></dt>
 <dd>
  This is redundant with an equivalent overload of <code>drawImage</code>.</dd>
 <dt>
  {{non-standard_inline}} <code>CanvasRenderingContext2D.setAlpha()</code></dt>
 <dd>
  Use {{domxref("CanvasRenderingContext2D.globalAlpha")}} instead.</dd>
 <dt>
  {{non-standard_inline}} <code>CanvasRenderingContext2D.setCompositeOperation()</code></dt>
 <dd>
  Use {{domxref("CanvasRenderingContext2D.globalCompositeOperation")}} instead.</dd>
 <dt>
  {{non-standard_inline}} <code>CanvasRenderingContext2D.setLineWidth()</code></dt>
 <dd>
  Use {{domxref("CanvasRenderingContext2D.lineWidth")}} instead.</dd>
 <dt>
  {{non-standard_inline}} <code>CanvasRenderingContext2D.setLineJoin()</code></dt>
 <dd>
  Use {{domxref("CanvasRenderingContext2D.lineJoin")}} instead.</dd>
 <dt>
  {{non-standard_inline}} <code>CanvasRenderingContext2D.setLineCap()</code></dt>
 <dd>
  Use {{domxref("CanvasRenderingContext2D.lineCap")}} instead.</dd>
 <dt>
  {{non-standard_inline}} <code>CanvasRenderingContext2D.setMiterLimit()</code></dt>
 <dd>
  Use {{domxref("CanvasRenderingContext2D.miterLimit")}} instead.</dd>
 <dt>
  {{non-standard_inline}} <code>CanvasRenderingContext2D.setStrokeColor()</code></dt>
 <dd>
  Use {{domxref("CanvasRenderingContext2D.strokeStyle")}} instead.</dd>
 <dt>
  {{non-standard_inline}} <code>CanvasRenderingContext2D.setFillColor()</code></dt>
 <dd>
  Use {{domxref("CanvasRenderingContext2D.fillStyle")}} instead.</dd>
 <dt>
  {{non-standard_inline}} <code>CanvasRenderingContext2D.setShadow()</code></dt>
 <dd>
  Use {{domxref("CanvasRenderingContext2D.shadowColor")}} and {{domxref("CanvasRenderingContext2D.shadowBlur")}} instead.</dd>
 <dt>
  {{non-standard_inline}} <code>CanvasRenderingContext2D.webkitLineDash</code></dt>
 <dd>
  Use {{domxref("CanvasRenderingContext2D.getLineDash()")}} and {{domxref("CanvasRenderingContext2D.setLineDash()")}} instead.</dd>
 <dt>
  {{non-standard_inline}} <code>CanvasRenderingContext2D.webkitLineDashOffset</code></dt>
 <dd>
  Use {{domxref("CanvasRenderingContext2D.lineDashOffset")}} instead.</dd>
 <dt>
  {{non-standard_inline}} <code>CanvasRenderingContext2D.webkitImageSmoothingEnabled</code></dt>
 <dd>
  Use {{domxref("CanvasRenderingContext2D.imageSmoothingEnabled")}} instead.</dd>
</dl>
<h3 id="Blink_only">Blink only</h3>
<dl>
 <dt>
  {{non-standard_inline}} <code>CanvasRenderingContext2D.getContextAttributes()</code></dt>
 <dd>
  Inspired by the same <code>WebGLRenderingContext</code> method it returns an <code>Canvas2DContextAttributes</code> object that contains the attributes "storage" to indicate which storage is used ("persistent" by default) and the attribute "alpha" (<code>true</code> by default) to indicate that transparency is used in the canvas.</dd>
 <dt>
  {{non-standard_inline}} <code>CanvasRenderingContext2D.isContextLost()</code></dt>
 <dd>
  Inspired by the same <code>WebGLRenderingContext</code> method it returns <code>true</code> if the Canvas context has been lost, or <code>false</code> if not.</dd>
</dl>
<h3 id="WebKit_only">WebKit only</h3>
<dl>
 <dt>
  {{non-standard_inline}} <code>CanvasRenderingContext2D.webkitBackingStorePixelRatio</code></dt>
 <dd>
  The backing store size in relation to the canvas element. See <a href="https://www.html5rocks.com/en/tutorials/canvas/hidpi/">High DPI Canvas</a>.</dd>
 <dt>
  {{non-standard_inline}} <code>CanvasRenderingContext2D.webkitGetImageDataHD</code></dt>
 <dd>
  Intended for HD backing stores, but removed from canvas specifications.</dd>
 <dt>
  {{non-standard_inline}} <code>CanvasRenderingContext2D.webkitPutImageDataHD</code></dt>
 <dd>
  Intended for HD backing stores, but removed from canvas specifications.</dd>
</dl>
<dl>
</dl>
<h3 id="Gecko_only">Gecko only</h3>
<dl>
 <dt>
  {{non-standard_inline}} {{domxref("CanvasRenderingContext2D.filter")}}</dt>
 <dd>
  <span id="summary_alias_container"><span id="short_desc_nonedit_display">CSS and SVG filters as Canvas APIs</span></span>. Likely to be standardized in a new version of the specification.</dd>
</dl>
<h4 id="Prefixed_APIs">Prefixed APIs</h4>
<dl>
 <dt>
  {{non-standard_inline}} <code>CanvasRenderingContext2D.mozCurrentTransform</code></dt>
 <dd>
  Sets or gets the current transformation matrix, see {{domxref("CanvasRenderingContext2D.currentTransform")}}.&nbsp; {{ gecko_minversion_inline("7.0") }}</dd>
 <dt>
  {{non-standard_inline}} <code>CanvasRenderingContext2D.mozCurrentTransformInverse</code></dt>
 <dd>
  Sets or gets the current inversed transformation matrix.&nbsp; {{ gecko_minversion_inline("7.0") }}</dd>
 <dt>
  {{non-standard_inline}} <code>CanvasRenderingContext2D.mozFillRule</code></dt>
 <dd>
  The <a class="external" href="https://cairographics.org/manual/cairo-cairo-t.html#cairo-fill-rule-t" title="https://cairographics.org/manual/cairo-cairo-t.html#cairo-fill-rule-t">fill rule</a> to use. This must be one of <code>evenodd</code> or <code>nonzero</code> (default).</dd>
 <dt>
  {{non-standard_inline}} <code>CanvasRenderingContext2D.mozImageSmoothingEnabled</code></dt>
 <dd>
  See {{domxref("CanvasRenderingContext2D.imageSmoothingEnabled")}}.</dd>
 <dt>
  {{non-standard_inline}} {{deprecated_inline}} <code>CanvasRenderingContext2D.mozDash</code></dt>
 <dd>
  An array which specifies the lengths of alternating dashes and gaps {{ gecko_minversion_inline("7.0") }}. Use {{domxref("CanvasRenderingContext2D.getLineDash()")}} and {{domxref("CanvasRenderingContext2D.setLineDash()")}} instead.</dd>
 <dt>
  {{non-standard_inline}} {{deprecated_inline}} <code>CanvasRenderingContext2D.mozDashOffset</code></dt>
 <dd>
  Specifies where to start a dash array on a line. {{ gecko_minversion_inline("7.0") }}. Use {{domxref("CanvasRenderingContext2D.lineDashOffset")}} instead.</dd>
 <dt>
  {{non-standard_inline}} {{deprecated_inline}} <code>CanvasRenderingContext2D.mozTextStyle</code></dt>
 <dd>
  Introduced in in Gecko 1.9, deprecated in favor of the {{domxref("CanvasRenderingContext2D.font")}} property.</dd>
 <dt>
  {{non-standard_inline}} {{obsolete_inline}} <code>CanvasRenderingContext2D.mozDrawText()</code></dt>
 <dd>
  This method was introduced in Gecko 1.9 and is removed starting with Gecko 7.0. Use {{domxref("CanvasRenderingContext2D.strokeText()")}} or {{domxref("CanvasRenderingContext2D.fillText()")}} instead.</dd>
 <dt>
  {{non-standard_inline}} {{obsolete_inline}} <code>CanvasRenderingContext2D.mozMeasureText()</code></dt>
 <dd>
  This method was introduced in Gecko 1.9 and is unimplemented starting with Gecko 7.0. Use {{domxref("CanvasRenderingContext2D.measureText()")}} instead.</dd>
 <dt>
  {{non-standard_inline}} {{obsolete_inline}} <code>CanvasRenderingContext2D.mozPathText()</code></dt>
 <dd>
  This method was introduced in Gecko 1.9 and is removed starting with Gecko 7.0.</dd>
 <dt>
  {{non-standard_inline}} {{obsolete_inline}} <code>CanvasRenderingContext2D.mozTextAlongPath()</code></dt>
 <dd>
  This method was introduced in Gecko 1.9 and is removed starting with Gecko 7.0.</dd>
</dl>
<h4 id="Internal_APIs_(chrome-context_only)">Internal APIs (chrome-context only)</h4>
<dl>
 <dt>
  {{non-standard_inline}} {{domxref("CanvasRenderingContext2D.asyncDrawXULElement()")}}</dt>
 <dd>
  Renders a region of a XUL element into the <code>canvas</code>.</dd>
 <dt>
  {{non-standard_inline}} {{domxref("CanvasRenderingContext2D.drawWindow()")}}</dt>
 <dd>
  Renders a region of a window into the <code>canvas</code>. The contents of the window's viewport are rendered, ignoring viewport clipping and scrolling.</dd>
 <dt>
  {{non-standard_inline}} <code>CanvasRenderingContext2D.demote()</code></dt>
 <dd>
  This causes a context that is currently using a hardware-accelerated backend to fallback to a software one. All state should be preserved.</dd>
</dl>
<h3 id="Internet_Explorer">Internet Explorer</h3>
<dl>
 <dt>
  {{non-standard_inline}} <code>CanvasRenderingContext2D.msFillRule</code></dt>
 <dd>
  The <a class="external" href="https://cairographics.org/manual/cairo-cairo-t.html#cairo-fill-rule-t" title="https://cairographics.org/manual/cairo-cairo-t.html#cairo-fill-rule-t">fill rule</a> to use. This must be one of <code>evenodd</code> or <code>nonzero</code> (default).</dd>
</dl>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('HTML WHATWG', "scripting.html#2dcontext:canvasrenderingcontext2d", "CanvasRenderingContext2D")}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td>&nbsp;</td>
  </tr>
 </tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<div>
 {{CompatibilityTable}}</div>
<div id="compat-desktop">
 <table class="compat-table">
  <tbody>
   <tr>
    <th>Feature</th>
    <th>Chrome</th>
    <th>Firefox (Gecko)</th>
    <th>Internet Explorer</th>
    <th>Opera</th>
    <th>Safari</th>
   </tr>
   <tr>
    <td>Basic support</td>
    <td>{{CompatChrome("1")}}</td>
    <td>{{CompatGeckoDesktop("1.8")}}</td>
    <td>{{CompatIE("9")}}</td>
    <td>{{CompatOpera("9")}}</td>
    <td>{{CompatSafari("2")}}</td>
   </tr>
  </tbody>
 </table>
</div>
<div id="compat-mobile">
 <table class="compat-table">
  <tbody>
   <tr>
    <th>Feature</th>
    <th>Android</th>
    <th>Chrome for Android</th>
    <th>Firefox Mobile (Gecko)</th>
    <th>IE Mobile</th>
    <th>Opera Mobile</th>
    <th>Safari Mobile</th>
   </tr>
   <tr>
    <td>Basic support</td>
    <td>{{CompatUnknown}}</td>
    <td>{{CompatUnknown}}</td>
    <td>{{CompatUnknown}}</td>
    <td>{{CompatUnknown}}</td>
    <td>{{CompatUnknown}}</td>
    <td>{{CompatUnknown}}</td>
   </tr>
  </tbody>
 </table>
</div>
<h2 id="See_also">See also</h2>
<ul>
 <li>{{domxref("HTMLCanvasElement")}}</li>
</ul>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h2 id="WIP">WIP</h2>
<p>------------------------------------------------------------------------------------------------------------------------------------------</p>
<p>Migrate the following into new subpages:</p>
<p>------------------------------------------------------------------------------------------------------------------------------------------</p>
<div class="note">
 <p><strong>Note:</strong> Starting in {{Gecko("5.0")}}, the following corrections were made to various behaviors in order to improve compliance with the HTML5 specification:</p>
 <ul>
  <li><code>getImageData()</code> now correctly accepts rectangles that extend beyond the bounds of the canvas; pixels outside the canvas are returned as transparent black.</li>
  <li><code>drawImage()</code>&nbsp;and <code>createImageData()</code> now handle negative arguments in accordance with the specification, by flipping the rectangle around the appropriate axis.</li>
  <li>Specifying non-finite values when calling <code>createImageData()</code> now properly throws a <code>NOT_SUPPORTED_ERR</code> exception.</li>
  <li><code>createImageData()</code>&nbsp;and <code>getImageData()</code> now correctly return at least one pixel's worth of image data if a rectangle smaller than one pixel is specified.</li>
  <li>Specifying a negative radius when calling <code>createRadialGradient()</code> now correctly throws <code>INDEX_SIZE_ERR</code>.</li>
  <li>Specifying a <code>null</code> or <code>undefined</code> image when calling <code>createPattern()</code>&nbsp;or <code>drawImage()</code> now correctly throws a <code>TYPE_MISMATCH_ERR</code> exception.</li>
  <li>Specifying invalid values for <code>globalAlpha</code> no longer throws a <code>SYNTAX_ERR</code> exception; these are now correctly silently ignored.</li>
  <li>Specifying invalid values when calling <code>translate()</code>, <code>transform()</code>, <code>rect()</code>, <code>clearRect()</code>, <code>fillRect()</code>, <code>strokeRect()</code>, <code>lineTo()</code>, <code>moveTo()</code>, <code>quadraticCurveTo()</code>, or <code>arc()</code> no longer throws an exception; these calls are now correctly silently ignored.</li>
  <li>Setting the value of <code>shadowOffsetX</code>, <code>shadowOffsetY</code>, or <code>shadowBlur</code> to an invalid value is now silently ignored.</li>
  <li>Setting the value of <code>rotate</code> or <code>scale</code> to an invalid value is now silently ignored.</li>
 </ul>
</div>
<p>&nbsp;</p>
Revert to this revision