Web/API/CanvasGradient

From Get docs

The CanvasGradient interface represents an opaque object describing a gradient. It is returned by the methods CanvasRenderingContext2D.createLinearGradient() or CanvasRenderingContext2D.createRadialGradient().

It can be used as a fillStyle or strokeStyle.

Properties

As an opaque object, there is no exposed property.

Methods

CanvasGradient.addColorStop()
Adds a new stop, defined by an offset and a color, to the gradient. If the offset is not between 0 and 1, inclusive, an INDEX_SIZE_ERR is raised; if the color can't be parsed as a CSS <color>, a SYNTAX_ERR is raised.

Specifications

Specification Status Comment
HTML Living StandardThe definition of 'CanvasGradient' in that specification. Living Standard

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
CanvasGradient Chrome

Full support 6

Edge

Full support 12

Firefox Full support 3.6

Notes'

Full support 3.6

Notes'

Notes' Before Firefox 5.0, specifying non-finite values when adding color stops through a call to addColorStop() incorrectly throws SYNTAX_ERR instead of INDEX_SIZE_ERR.

IE

Full support 9

Opera

Full support 9

Safari

Full support 5.1

WebView Android

Full support ≤37

Chrome Android

Full support 18

Firefox Android

Full support 4

Opera Android

Full support 10.1

Safari iOS

Full support 6

Samsung Internet Android

Full support 1.0

addColorStop Chrome

Full support 6

Edge

Full support 12

Firefox

Full support 3.6

IE

Full support 9

Opera

Full support 9

Safari

Full support 5.1

WebView Android

Full support ≤37

Chrome Android

Full support 18

Firefox Android

Full support 4

Opera Android

Full support 10.1

Safari iOS

Full support 6

Samsung Internet Android

Full support 1.0

Legend

Full support  
Full support
See implementation notes.'
See implementation notes.


See also