Run ❯
Get your
own
website
Result Size:
625 x 565
×
Change Orientation
Save Code
Change Theme, Dark/Light
Go to Spaces
<!DOCTYPE html> <html> <body> <h1>HTML5 Canvas</h1> <h2>The strokeText() Method</h2> <canvas id="myCanvas" width="300" height="150" style="border:1px solid grey"></canvas> <script> const c = document.getElementById("myCanvas"); const ctx = c.getContext("2d"); ctx.font = "20px Georgia"; ctx.strokeText("Hello World!", 10, 50); ctx.font = "30px Verdana"; // Create gradient var gradient = ctx.createLinearGradient(0, 0, c.width, 0); gradient.addColorStop("0", "magenta"); gradient.addColorStop("0.5", "blue"); gradient.addColorStop("1.0", "red"); // Fill with gradient ctx.strokeStyle = gradient; ctx.strokeText("Big smile!", 10, 90); </script> </body> </html>