<!DOCTYPE html> <html> <body> <canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3;"> Your browser does not support the HTML5 canvas tag. </canvas> <script> var c=document.getElementById("myCanvas"); var ctx=c.getContext("2d"); ctx.font="20px '黑体'"; ctx.fillText("Hello World!",10,120); ctx.font="30px Arial"; // Create gradient var gradient=ctx.createLinearGradient(0,0,c.width,0); gradient.addColorStop("0","tomato"); gradient.addColorStop("0.5","cyan"); gradient.addColorStop("1.0","tan"); // Fill with gradient ctx.fillStyle=gradient; ctx.fillText("小菜分享",10,90); </script> </body> </html>