Define a gradient (left to right) that goes from black to white, as the fill style for the rectangle:
JavaScript:
![]()
Internet Explorer 9, Firefox, Opera, Chrome, and Safari support the createLinearGradient() method.
Note: Internet Explorer 8 and earlier versions, do not support the <canvas> element.
The createLinearGradient() method creates a linear gradient object.
The gradient can be used to fill rectangles, circles, lines, text, etc.
Tip: Use this object as the value to the strokeStyle or fillStyle properties.
Tip: Use the addColorStop() method to specify different colors, and where to position the colors in the gradient object.
| JavaScript syntax: | context.createLinearGradient(x0,y0,x1,y1); |
|---|
| Parameter | Description |
|---|---|
| x0 | The x-coordinate of the start point of the gradient |
| y0 | The y-coordinate of the start point of the gradient |
| x1 | The x-coordinate of the end point of the gradient |
| y1 | The y-coordinate of the end point of the gradient |
Define a gradient (top to bottom) as the fill style for the rectangle:
JavaScript:
Define a gradient that goes from black, to red, to white, as the fill style for the rectangle:
JavaScript:
HTML Canvas Reference
Your message has been sent to W3Schools.