Get your own website Result Size: 625 x 565
x
 
<!DOCTYPE html>
<html>
<body>
<h1>HTML5 Canvas</h1>
<h2>The textAlign Property</h2>
<canvas id="myCanvas" width="300" height="200" style="border:1px solid grey"></canvas>
<script>
const c = document.getElementById("myCanvas");
const ctx = c.getContext("2d");
// Create a red line in position 150
ctx.strokeStyle = "red";
ctx.moveTo(150, 20);
ctx.lineTo(150, 170);
ctx.stroke();
ctx.font = "15px Arial";  
// Show the different textAlign values
ctx.textAlign = "start";    
ctx.fillText("textAlign=start", 150, 60);    
ctx.textAlign = "end";    
ctx.fillText("textAlign=end", 150, 80);          
ctx.textAlign = "left";    
ctx.fillText("textAlign=left", 150, 100);
ctx.textAlign = "center";   
ctx.fillText("textAlign=center",150, 120);        
ctx.textAlign = "right";    
ctx.fillText("textAlign=right",150, 140);
</script>
</body>
</html>