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
There is no inherited method.
CanvasGradient.addColorStop()- Adds a new stop, defined by an
offsetand acolor, to the gradient. If the offset is not between0and1, inclusive, anINDEX_SIZE_ERRis raised; if the color can't be parsed as a CSS<color>, aSYNTAX_ERRis raised.
Specifications
| Specification | Status | Comment |
|---|---|---|
| HTML Living Standard The definition of 'CanvasGradient' in that specification. |
Living Standard |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
CanvasGradient | Chrome Full support 4 | Edge Full support 12 | Firefox
Full support
3.6
| IE Full support 9 | Opera Full support 9 | Safari Full support 3.1 | WebView Android Full support Yes | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 10.1 | Safari iOS Full support 3.2 | Samsung Internet Android Full support 1.0 |
addColorStop | Chrome Full support Yes | Edge Full support 12 | Firefox Full support 3.6 | IE Full support Yes | Opera Full support Yes | Safari Full support Yes | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support Yes |
Legend
- Full support
- Full support
- See implementation notes.
- See implementation notes.
See also
- Creator methods in
CanvasRenderingContext2D. - The
<canvas>element and its associated interface,HTMLCanvasElement.
