Canvas textAlign: Align Text Around the X Coordinate

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);

Compare textAlign values Top ↑

Canvas text alignment demo.

How each alignment works Top ↑

ValueAlignment point
leftx is the left edge
rightx is the right edge
centerx is the center
startStart side based on text direction
endEnd side based on text direction

start and end follow text direction Top ↑

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.

Frequently asked questions Top ↑

What is the default textAlign value? Top ↑

The default is start.

Does textAlign move the Canvas coordinate system? Top ↑

No. It changes how text is positioned around the x coordinate.

What is the difference between left and start? Top ↑

left is physically left; start depends on the current text direction.

How do I center Canvas text at x=250? Top ↑

Set ctx.textAlign = "center" and draw the text using x=250.

Does textAlign affect text already drawn? Top ↑

No. It affects subsequent text drawing operations.

fillText() | textBaseline | font | Text demo | Canvas tutorial





plus2net.com










We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2026   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer