Source Code:
(back to article)
Submit
Result:
Report an issue
<!DOCTYPE html> <html> <head> <title>Title of the document</title> <style> canvas { border: 1px solid #cccccc; } </style> </head> <body> <canvas id="exampleCanvas" width="300" height="150"> Your browser doesn't support the HTML5 canvas tag. </canvas> <script> var c = document.getElementById("exampleCanvas"); var ctx = c.getContext("2d"); var grd = ctx.createLinearGradient(0, 0, 300, 0); grd.addColorStop(0, "green"); grd.addColorStop(1, "whitesmoke"); ctx.fillStyle = grd; ctx.fillRect(20, 20, 260, 110); </script> </body> </html>