The CanvasGradient interface represents an opaque object describing a gradient. It is returned by the methods CanvasRenderingContext2D.createLinearGradient() or CanvasRenderingContext2D.createRadialGradient().
Properties
Representing 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 between0and1anINDEX_SIZE_ERRis raised, if the color can't be parsed as a CSS<color>, aSYNTAX_ERRis raised.
Specifications
| Specification | Status | Comment | 
|---|---|---|
| WHATWG HTML Living Standard The definition of 'CanvasGradient' in that specification. | Living Standard | 
Browser compatibility
| Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari | 
|---|---|---|---|---|---|---|
| Basic support | 4.0 | (Yes) | 3.6 (1.9.2) [1] | 9.0 | 9.0 | 3.1 | 
| Feature | Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile | 
|---|---|---|---|---|---|---|
| Basic support | 2.1 | (Yes) | 1.0 (1.9.2) [1] | ? | 10.0 | 3.2 | 
[1] Before Gecko 5.0, (Firefox 5.0 / Thunderbird 5.0 / SeaMonkey 2.2), specifying non-finite values when adding color stops through a call to addColorStop() incorrectly throws SYNTAX_ERR instead of INDEX_SIZE_ERR.
See also
- Creator methods in CanvasRenderingContext2D.
- The <canvas>element and its associated interface,HTMLCanvasElement.
Document Tags and Contributors
    
    Tags: 
    
  
                    
                       Contributors to this page: 
        erikadoyle, 
        Sebastianz, 
        fscholz, 
        tschneidereit, 
        kscarfone, 
        teoli, 
        Sheppy, 
        ethertank, 
        Brettz9
                    
                    
                       Last updated by:
                      erikadoyle,