The Canvas textAlign property controls how text is horizontally positioned around the x coordinate passed to fillText() or strokeText().
Valid values are start, end, left, right, and center. The default is start.
ctx.textAlign = 'center';
ctx.fillText('plus2net.com', 250, 100);
| Value | Alignment point |
|---|---|
left | x is the left edge |
right | x is the right edge |
center | x is the center |
start | Start side based on text direction |
end | End side based on text direction |
Use start and end when the alignment should adapt to left-to-right or right-to-left text. If directionality matters, set or inherit the Canvas text direction deliberately.
The default is start.
No. It changes how text is positioned around the x coordinate.
left is physically left; start depends on the current text direction.
Set ctx.textAlign = "center" and draw the text using x=250.
No. It affects subsequent text drawing operations.
fillText() | textBaseline | font | Text demo | Canvas tutorial
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.