HTML | canvas textAlign Property

The HTML canvas textAlign Property is used to set or return the current alignment for text content, according to the anchor point. Basically, the text will start at that position and the text will end at that specified position.


 context.textAlign="center | end | left | right | start"; 

Property Values:

  • start: It has a Default. The text starts at the specified position.
  • end: The text ends at the specified position.
  • left: It is used to set the text-alignment into left.
  • right: It is used to set the text-alignment into right.
  • center: It is used to set the text-alignment into the center.






<!DOCTYPE html>
        h2 {
            color: green;
        body {
            text-align: center;
    <h2>HTML canvas textAlign Property </h2>
    <canvas id="sudo"
            style="border:3px solid red;">
        Your browser does not support the HTML5 canvas tag.
        var c = document.getElementById("sudo");
        var ctx = c.getContext("2d");
        // Create a blue line in position 170
        ctx.strokeStyle = "blue";
        ctx.moveTo(170, 20);
        ctx.lineTo(170, 170);
        ctx.font = "15px Arial";
        // Show the different textAlign values
        ctx.textAlign = "start";
        ctx.fillText("start", 170, 60);
        ctx.textAlign = "end";
        ctx.fillText("end", 170, 80);
        ctx.textAlign = "left";
        ctx.fillText("left", 170, 100);
        ctx.textAlign = "center";
        ctx.fillText("center", 170, 120);
        ctx.textAlign = "right";
        ctx.fillText("right", 170, 140);



Supported Browsers: The browsers supported by HTML canvas textAlign Property are listed below:

  • Google Chrome
  • Internet Explorer 9.0
  • Firefox
  • Apple Safari
  • Opera


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.