Repository navigation
Description
Description
Note this was previously submitted for interop 2023 (#159), 2024 (#427) and 2025 (#817). This time it is being submitted as an investigation effort proposal.
A long-standing problem that has been painful for us for some years now is browsers don't agree on how to align text when drawing to a canvas. Further, TextMetrics gives three different answers in different browsers for values like fontBoundingBoxAscent/Descent depending on the text baseline - in one case we get three different sets of values across Chrome, Firefox and Safari. In some situations that makes the API pretty much useless, since you can't achieve things like consistent alignment across browsers.
Positioning text precisely on canvases is important for things like buttons and text layout. For example a canvas game may have a text label drawn on top of a button graphic with a border. Carefully placing the text so it's aligned correctly in one browser will still show it misaligned in another browser. There doesn't seem to be any good workaround to this.
TextMetrics is important for things like canvas text layout. If you want to draw some text on a canvas vertically aligned inside a box, you may need to take in to account the fontBoundingBoxAscent/Descent. However those values return inconsistent values across browsers, which basically makes the API useless for precisely aligning text. You have to pick one browser to display it right and the others will be wrong.
Rationale
This is important for any kind of precise text alignment when drawing text to a canvas. It is important for the web-based game development tool Construct and likely other cases where text layout on canvas is important (e.g. canvas-based word processors or design tools).
Sample complaints from developers (just a selection of many such reports):
Scirra/Construct-bugs#6137
Scirra/Construct-bugs#6255
Scirra/Construct-bugs#7164
In the survey in #246 "Canvas text rendering" was selected by ~15% of survey takers.
Investigation Roadmap
The main canvas specification is here: https://html.spec.whatwg.org/multipage/canvas.html
The following browser issues have been filed:
https://issues.chromium.org/issues/40769053
https://issues.chromium.org/issues/40752202
https://bugs.webkit.org/show_bug.cgi?id=226334
Discussion of these led to filing the following specification issue: whatwg/html#6731
This references the following other specification issues/PRs:
whatwg/html#2470
whatwg/html#5826
whatwg/html#5830
It appears the open specification issues need to be resolved, and it looks like tests also need to be written once the specification issues have been cleared up.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
lsalzman commentedon Jan 8, 2026
@annevk Anne, do you know how we stand on this issue in terms of the unresolved spec issues and whether Chrome/Safari are willing to resolve this?
annevk commentedon Jan 9, 2026
As far as I can tell whatwg/html#5830 is a feature request without activity, whatwg/html#6731 is asking for better test coverage which still needs to be done by someone (tm), and the other two issues have already been resolved. I can't really commit on behalf of WebKit for Interop 2026, but we are generally interested in making this behave better.
cc @schenney-chromium
schenney-chromium commentedon Jan 9, 2026
I just commented on whatwg/html#6731 about Chrome canvas text baseline tests differing cross platform, even for the same font loaded from the same location. Maybe this is not just a browser compat issue but something farther down the stack, though the initial report suggests otherwise. Or maybe Chrome is misbehaving on Mac.
@drott do you know why this might be the case?
See the results from this particular version of my writing mode CL: https://chromium-review.googlesource.com/c/chromium/src/+/7310865/4?tab=checks
wpt-interop commentedon Feb 12, 2026
Thank you for proposing Canvas text rendering and metrics (2026 edition) for Interop 2026.
We want to let you know it was not selected to be part of Interop this year.
On behalf of the entire Interop team, thank you for submitting it for consideration. We got many more proposals than we could include in this year's project, necessitating some difficult choices. Please note this should not be taken as a comment on the technology as a whole, or our willingness to consider it for Interop in the future. We appreciate the work you put into your proposal, and would welcome your participation in future rounds of Interop.
Posted on behalf of the Interop team.
tweak workaround for safari canvas text bug