Skip to content

Technical review: Document HTML-in-Canvas - #46289

Open
chrisdavidmills wants to merge 24 commits into
mdn:mainfrom
chrisdavidmills:html-in-canvas
Open

chrisdavidmills wants to merge 24 commits into
mdn:mainfrom
chrisdavidmills:html-in-canvas

Conversation

@chrisdavidmills

@chrisdavidmills chrisdavidmills commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Description

Chrome 157 adds support for the HTML-in-Canvas API; see https://chromestatus.com/feature/5172548013916160.

This PR documents HTML-in-Canvas.

Written Tech review Approved Editorial review Approved
Main landing page ✅ ✅ (pr, sc)
<canvas> element content attribute ✅
HTML global drawable attribute ✅ ✅ (pr)
HTMLCanvasElement interface landing page ✅ ✅ (pr,sc)
HTMLCanvasElement.content and HTMLElement.drawable properties ✅
HTMLCanvasElement.captureElementImage() method ✅
HTMLCanvasElement.getElementImageDefaultSize() method ✅ ✅ (sc)
HTMLCanvasElement.requestPaint() method ✅ ✅ (sc)
HTMLCanvasElement.updateElementGeometry() method ✅
HTMLCanvasElement.clearElementGeometry() method ✅
HTMLCanvasElement.getElementTransform() method ✅
HTMLCanvasElement paint event ✅ ✅ (pr, sc)
HTMLCanvasElement elementgeometryupdate event ✅
OffscreenCanvas.updateElementGeometry() method ✅
OffscreenCanvas.getElementImageDefaultSize() method ✅
OffscreenCanvas.clearElementGeometry() method ✅
SVG drawable global attribute and SVGElement drawable property ✅
MathML drawable global attribute and MathMLElement drawable property ✅
CanvasRenderingContext2D.drawElementImage() method ✅
OffscreenCanvasRenderingContext2D.drawElementImage() method ✅
WebGLRenderingContext.texElementSubImage2D() method ✅
GPUQueue.drawElementImageToTexture() method ✅
CanvasPaintEvent interface and members ✅ ✅ (pr, sc)
ElementGeometryUpdateEvent interface and members ✅
ElementImage interface and members ✅ ✅ (sc)

Motivation

Additional details

Related issues and pull requests

@chrisdavidmills
chrisdavidmills requested review from a team as code owners October 26, 2026 19:05
@chrisdavidmills
chrisdavidmills requested review from hamishwillee and pepelsbey and removed request for a team October 26, 2026 19:05
@github-actions github-actions Bot added the Content:WebAPI Web API docs label Oct 26, 2026
@chrisdavidmills chrisdavidmills changed the title Document HTML-in-Canvas Technical review: Document HTML-in-Canvas Oct 26, 2026
@github-actions github-actions Bot added the size/m [PR only] 51-500 LoC changed label Oct 26, 2026
@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor
Preview URLs (48 pages)
Flaws (48)

Note! 38 documents with no flaws that don't need to be listed. 🎉

Found an unexpected or unresolvable flaw? Please report it here.

URL: /en-US/docs/Web/API/HTMLCanvasElement
Title: HTMLCanvasElement
Flaw count: 1

  • macros:
    • Macro domxref produces link /en-US/docs/Web/API/HTMLCanvasElement/mozPrintCallback which doesn't resolve

URL: /en-US/docs/Web/API/HTMLCanvasElement/paint_event
Title: HTMLCanvasElement: paint event
Flaw count: 1

  • macros:
    • Macro domxref produces link /en-US/docs/Web/API/GlobalEventHandlers/paint_event which doesn't resolve

URL: /en-US/docs/Web/API/HTMLElement/drawable
Title: HTMLElement: drawable property
Flaw count: 1

  • macros:
    • Unknown browser-compat entry: api.HTMLElement.drawable

URL: /en-US/docs/Web/API/MathMLElement/drawable
Title: MathMLElement: drawable property
Flaw count: 1

  • macros:
    • Unknown browser-compat entry: api.MathMLElement.drawable

URL: /en-US/docs/Web/API/SVGElement
Title: SVGElement
Flaw count: 1

  • macros:
    • Macro domxref produces link /en-US/docs/Web/API/SVGElement/className which doesn't resolve

URL: /en-US/docs/Web/API/SVGElement/drawable
Title: SVGElement: drawable property
Flaw count: 1

  • macros:
    • Unknown browser-compat entry: api.SVGElement.drawable

URL: /en-US/docs/Web/HTML/Reference/Attributes
Title: HTML attribute reference
Flaw count: 34

  • broken_links:
    • Link /en-US/docs/Web/HTML/Reference/Attributes/alt doesn't resolve
    • Link /en-US/docs/Web/HTML/Reference/Attributes/autoplay doesn't resolve
    • Link /en-US/docs/Web/HTML/Reference/Attributes/cite doesn't resolve
    • Link /en-US/docs/Web/HTML/Reference/Attributes/colspan doesn't resolve
    • Link /en-US/docs/Web/HTML/Reference/Attributes/controls doesn't resolve
    • and 29 more flaws omitted

URL: /en-US/docs/Web/MathML/Reference/Global_attributes
Title: MathML global attributes
Flaw count: 6

  • broken_links:
    • Link /en-US/docs/Web/MathML/Reference/Global_attributes/autofocus doesn't resolve
    • Link /en-US/docs/Web/MathML/Reference/Global_attributes/class doesn't resolve
    • Link /en-US/docs/Web/MathML/Reference/Global_attributes/id doesn't resolve
    • Link /en-US/docs/Web/MathML/Reference/Global_attributes/nonce doesn't resolve
    • Link /en-US/docs/Web/MathML/Reference/Global_attributes/style doesn't resolve
    • and 1 more flaws omitted

URL: /en-US/docs/Web/MathML/Reference/Global_attributes/drawable
Title: drawable
Flaw count: 1

  • macros:
    • Unknown browser-compat entry: mathml.global_attributes.drawable

URL: /en-US/docs/Web/SVG/Reference/Attribute/drawable
Title: drawable
Flaw count: 1

  • macros:
    • Unknown browser-compat entry: svg.global_attributes.drawable
External URLs (19)

URL: /en-US/docs/Web/API/ElementGeometryUpdateEvent
Title: ElementGeometryUpdateEvent


URL: /en-US/docs/Web/API/GPUQueue/drawElementImageToTexture
Title: GPUQueue: drawElementImageToTexture() method


URL: /en-US/docs/Web/API/HTML-in-Canvas_API
Title: HTML-in-Canvas API


URL: /en-US/docs/Web/API/HTMLCanvasElement/clearElementGeometry
Title: HTMLCanvasElement: clearElementGeometry() method


URL: /en-US/docs/Web/API/HTMLCanvasElement/elementgeometryupdate_event
Title: HTMLCanvasElement: elementgeometryupdate event


URL: /en-US/docs/Web/API/HTMLCanvasElement/paint_event
Title: HTMLCanvasElement: paint event


URL: /en-US/docs/Web/API/HTMLCanvasElement/updateElementGeometry
Title: HTMLCanvasElement: updateElementGeometry() method


URL: /en-US/docs/Web/API/OffscreenCanvas/clearElementGeometry
Title: OffscreenCanvas: clearElementGeometry() method


URL: /en-US/docs/Web/API/OffscreenCanvas/getElementImageDefaultSize
Title: OffscreenCanvas: getElementImageDefaultSize() method


URL: /en-US/docs/Web/API/OffscreenCanvas/updateElementGeometry
Title: OffscreenCanvas: updateElementGeometry() method


URL: /en-US/docs/Web/API/OffscreenCanvasRenderingContext2D/drawElementImage
Title: OffscreenCanvasRenderingContext2D: drawElementImage() method


URL: /en-US/docs/Web/API/WebGLRenderingContext/texElementSubImage2D
Title: WebGLRenderingContext: texElementSubImage2D() method


URL: /en-US/docs/Web/HTML/Reference/Global_attributes/drawable
Title: drawable HTML global attribute


URL: /en-US/docs/Web/MathML/Reference/Global_attributes/drawable
Title: drawable


URL: /en-US/docs/Web/SVG/Reference/Attribute/drawable
Title: drawable

(comment last updated: 2026-11-26 17:03:57)

@chrisdavidmills
chrisdavidmills requested a review from a team as a code owner October 28, 2026 16:08
@github-actions github-actions Bot added the Content:HTML Hypertext Markup Language docs label Oct 28, 2026
@github-actions github-actions Bot added size/l [PR only] 501-1000 LoC changed and removed size/m [PR only] 51-500 LoC changed labels Oct 30, 2026
@github-actions github-actions Bot added size/xl [PR only] >1000 LoC changed and removed size/l [PR only] 501-1000 LoC changed labels Nov 2, 2026

### Reporting on which elements were painted

This example shows how to render DOM elements onto a 2D canvas, and how the `paint` event can be used to expose data on what elements were repainted each time the event fires.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An important aspect of the paint event is that dom/css changes made in it do not show up in the current frame, and dom/css changes do not affect how elements are drawn (e.g., with drawElementImage), but canvas drawings made in the paint event DO show up in the current frame. Would you like to include something like that here?

A pattern we are encouraging developers to follow is to switch their requestAnimationFrame loops over to paint+requestPaint loops. Would you like to mention that? In other words, developers using html-in-canvas may want to change:

function update() {
  // update state
  // draw
  requestAnimationFrame(update);
}
requestAnimationFrame(update);

To this:

canvas.onpaint = (e) => {
  // update state
  // draw
  canvas.requestPaint();
};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually talk about this stuff in the paint event reference page, as I thought that would be a better place for it. I've added a few details, but let me know if you think I've got anything wrong there.

I also updated all of my demos at mdn/dom-examples#406 to use the paint/requestPaint pattern rather than rAF, so that all of my stuff is consistent.

I think the main thing wrong with my demos currently is that on the WebGL/WebGPU demos, you can tab to the form and fill it out, but you can't click into the form with the mouse because I'm not updating the form geometry.

I think the best way for me to update this would be to stop the cube rotation when the canvas is moused over, and then update the form geometry to the front cube face as seen when rotation is paused. To do this, I guess I'd need to figure out the DOMMatrix to apply to do this, then clear the geometry when the cube starts spinning again. What do you think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the explainer we have an example of the 3D geometry update for hit testing. It uses a particularly simple situation to make extracting the matrix easier, but you could certainly adapt it to work in more complex cases.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@schenney-chromium which example should I be looking at to find this?

I managed to work out some code for this myself, with a little help from Claude, but I am wondering if it is the best or most efficient way to do this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can see my work in mdn/dom-examples#406.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example is https://github.com/WICG/html-in-canvas/blob/main/Examples/webGL.html

I'll take a look at yours but I too am not an expert in WebGL coding.

@schenney-chromium schenney-chromium left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for working on this.

In addition to the comments here, the drawable attribute also applies to SVGElement and MathMLElement. The former is still an open spec issue, while the latter has agreement from the MATHML Core folks (though it's not in the spec yet as far as I know).


### Reporting on which elements were painted

This example shows how to render DOM elements onto a 2D canvas, and how the `paint` event can be used to expose data on what elements were repainted each time the event fires.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the explainer we have an example of the 3D geometry update for hit testing. It uses a particularly simple situation to make extracting the matrix easier, but you could certainly adapt it to work in more complex cases.


{{APIRef("Canvas API")}}

The **`getElementImageDefaultSize()`** method of the {{domxref("HTMLCanvasElement")}} interface returns an object containing an element's original size as it would be rendered in the DOM, once rendered using the [HTML-in-Canvas API](/en-US/docs/Web/API/HTML-in-Canvas_API). The returned size is in canvas grid coordinates.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

".. an object containing an element's original size as it ..."

We had so many conversations to figure out how best to explain this size!

".. an object containing the default size, in canvas pixels, of an ElementImage when drawn with drawElementImage and no destination rect."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right ;-)

I played around with your suggestion a bit, and ended up with:

The getElementImageDefaultSize() method of the {{domxref("HTMLCanvasElement")}} interface returns an object containing the default size, in canvas units, of an element when drawn with {{domxref("CanvasRenderingContext2D.drawElementImage", "drawElementImage()")}} (specifying no destination size).

Does this work? I used "canvas units" instead of "canvas pixels", as that's what I've said elsewhere.

@chrisdavidmills

Copy link
Copy Markdown
Contributor Author

@schenney-chromium, thanks for the review work!

In addition to the comments here, the drawable attribute also applies to SVGElement and MathMLElement. The former is still an open spec issue, while the latter has agreement from the MATHML Core folks (though it's not in the spec yet as far as I know).

This is good to know. Are these implemented yet? Which version are they available in? Behind a pref?

If they aren't in the specs yet, we can always include them on MDN with a "non-standard" flag for now.

@chrisdavidmills

Copy link
Copy Markdown
Contributor Author

Thanks a lot for the reviews so far, @progers and @schenney-chromium. I've answered all your comments so far. The table in the description shows which pages still need a tech review (for reviewed pages, I've included your initials so you know who has looked at what).

@schenney-chromium

Copy link
Copy Markdown
Contributor

@schenney-chromium, thanks for the review work!

In addition to the comments here, the drawable attribute also applies to SVGElement and MathMLElement. The former is still an open spec issue, while the latter has agreement from the MATHML Core folks (though it's not in the spec yet as far as I know).

This is good to know. Are these implemented yet? Which version are they available in? Behind a pref?

If they aren't in the specs yet, we can always include them on MDN with a "non-standard" flag for now.

I checked for tests and we do have examples that work but nothing for MathML, although I see no reason for it to fail. I should create a MathML test case to verify.

The attribute is not in the SVG or MathML specs yet. There is no special flag and I suspect they have always "just worked".

@schenney-chromium schenney-chromium left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good. Is there a preview page somewhere? I would like to do a final review pass on the content as it will appear on MDN.

@hamishwillee

Copy link
Copy Markdown
Collaborator

The changes look good. Is there a preview page somewhere? I would like to do a final review pass on the content as it will appear on MDN.

@schenney-chromium In theory every PR generates one (though they can disappear after a few weeks if there are not edits). In this case you can find the links in #46289 (comment)

@schenney-chromium

Copy link
Copy Markdown
Contributor

The changes look good. Is there a preview page somewhere? I would like to do a final review pass on the content as it will appear on MDN.

@schenney-chromium In theory every PR generates one (though they can disappear after a few weeks if there are not edits). In this case you can find the links in #46289 (comment)

Thanks. I should have known that from HTML specs. I'll try to do a final technical review pass on the pages that are ready in the next couple of days.

Once again I appreciate the effort you're all putting into this work.

@github-actions github-actions Bot added Content:SVG SVG docs Content:MathML MathML docs labels Nov 16, 2026
@chrisdavidmills

chrisdavidmills commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

I checked for tests and we do have examples that work but nothing for MathML, although I see no reason for it to fail. I should create a MathML test case to verify.

The attribute is not in the SVG or MathML specs yet. There is no special flag and I suspect they have always "just worked".

@schenney-chromium I've added reference pages for the SVG and MathML drawable global attributes and their DOM interface property equivalents.

I tested the element attributes to make sure you can nest SVG/MathML elements inside a <canvas> element, give them drawable, and then use the API to draw them on the canvas context. This all works fine, no problem.

However, when I try to get or set the values of HTMLElement.drawable, SVGElement.drawable, and MathMLElement.drawable in JavaScript, I get undefined returned. Is this a bug, or is it expected behavior? Can you look at my draft reference pages and let me know if I'm doing anything wrong?

@schenney-chromium

Copy link
Copy Markdown
Contributor

I checked for tests and we do have examples that work but nothing for MathML, although I see no reason for it to fail. I should create a MathML test case to verify.
The attribute is not in the SVG or MathML specs yet. There is no special flag and I suspect they have always "just worked".

@schenney-chromium I've added reference pages for the SVG and MathML drawable global attributes and their DOM interface property equivalents.

I tested the element attributes to make sure you can nest SVG/MathML elements inside a <canvas> element, give them drawable, and then use the API to draw them on the canvas context. This all works fine, no problem.

Thanks.

However, when I try to get or set the values of HTMLElement.drawable, SVGElement.drawable, and MathMLElement.drawable in JavaScript, I get undefined returned. Is this a bug, or is it expected behavior? Can you look at my draft reference pages and let me know if I'm doing anything wrong?

I'll take a look at this., and learn something along the way. I'm not sure what the expected behavior is for attributes that do not take a value, that is drawable vs. drawable=true.

@chrisdavidmills
chrisdavidmills marked this pull request as ready for review November 17, 2026 12:51
@chrisdavidmills
chrisdavidmills requested review from a team as code owners November 17, 2026 12:51
@chrisdavidmills

Copy link
Copy Markdown
Contributor Author

@schenney-chromium @progers @ewewraw great news — I've finished all the HTML-in-Canvas reference articles. There's quite a bit still to tech review — refer to the table at the top to see which ones you've looked at and which ones are still to do.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:HTML Hypertext Markup Language docs Content:MathML MathML docs Content:SVG SVG docs Content:WebAPI Web API docs size/xl [PR only] >1000 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants