HTML canvas createRadialGradient() method
Definition and Usage
createLinearGradient()
method to create a radial/circular gradient object.
Gradients can be used to fill rectangles, circles, lines, text, and more.
Hint:Please use the object as strokeStyle or fillStyle the value of the property.
Hint:Please use addColorStop() The method specifies different colors and where to locate the colors in the gradient object.
Example
Draw a rectangle and fill it with a radial/circular gradient:
JavaScript:
var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d"); var grd =ctx.createRadialGradient(75, 50, 5, 90, 60, 100); grd.addColorStop(0, "red"); grd.addColorStop(1, "white"); // Fill with gradient ctx.fillStyle = grd; ctx.fillRect(10,10,150,100);
Syntax
context.createRadialGradient(x0,y0,r0,x1,y1,r1);
Parameter Value
Parameter | Description |
---|---|
x0 | The x-coordinate of the start circle of the gradient |
y0 | The y-coordinate of the start circle of the gradient |
r0 | Radius of the start circle |
x1 | The x-coordinate of the end circle of the gradient |
y1 | The y-coordinate of the end circle of the gradient |
r1 | Radius of the end circle |
Browser Support
The numbers in the table indicate the first browser version that fully supports this property.
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
4.0 | 9.0 | 3.6 | 4.0 | 10.1 |
Note:Internet Explorer 8 and earlier versions do not support the <canvas> element.