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 acolor
, to the gradient. If the offset is not between0
and1
, inclusive, anINDEX_SIZE_ERR
is raised; if the color can't be parsed as a CSS<color>
, aSYNTAX_ERR
is raised.
Specifications
Specification | Status | Comment |
---|---|---|
HTML Living StandardThe 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.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
CanvasGradient
|
Chrome
Full support 6 |
Edge
Full support 12 |
Firefox Full support 3.6 Full support 3.6 Notes' Before Firefox 5.0, specifying non-finite values when adding color stops through a call to |
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
- Creator methods in
CanvasRenderingContext2D
. - The
<canvas>
element and its associated interface,HTMLCanvasElement
.
CanvasGradient by Mozilla Contributors is licensed under CC-BY-SA 2.5.