HTMLSource and ElementImageSource turn a DOM element into a TextureSource you can use anywhere a normal texture works: on a Sprite, as a Texture frame, or mapped onto a Mesh. HTMLSource mirrors a live element's pixels into the GPU (the element stays editable and clickable in the browser); ElementImageSource wraps an immutable snapshot that never repaints. Both live in pixi.js/html-source; importing from that path registers their extensions.
These sources rely on the experimental HTML-in-Canvas browser proposal and are marked EXPERIMENTAL in PixiJS v8. The browser API must be enabled or the texture uploader throws on first render; feature-detect with
canvas.requestPaintbefore relying on it. The API may change between minor releases.
Assumes familiarity with pixijs-scene-sprite and textures. These are texture sources, not display objects: wrap them in a Sprite (or Texture/Mesh) to put them on screen. Not available in Web Workers; a worker has no DOM to capture.
Quick Start
Related skills: pixijs-scene-sprite (display the texture), pixijs-scene-mesh (map onto geometry, PerspectiveMesh), pixijs-scene-dom-container (the opposite: overlay HTML above the canvas, outside the GPU pipeline), pixijs-assets (texture sources vs the loader/cache), pixijs-environments (no DOM in Web Workers).
Constructor options
Both sources extend TextureSource, so all TextureSourceOptions (resolution, scaleMode, addressMode, label, etc.) are valid. resource is required on each.
HTMLSourceOptions (live element):
ElementImageSourceOptions (immutable snapshot):
Change the defaults for every HTMLSource through the static HTMLSource.defaultOptions object, for example HTMLSource.defaultOptions.autoUpdate = false.
Core Patterns
Setup and the side-effect import
pixi.js/html-source calls extensions.add(...) to register HTMLSource, ElementImageSource, and their WebGL/WebGPU uploaders. Without it, the renderer has no 'html' uploader and these sources never render. The classes are exported from pixi.js/html-source, not pixi.js.
Importing a named export from pixi.js/html-source also triggers the side effect, so a bare import 'pixi.js/html-source' is only needed when you don't import anything else from that path.
Feature detection and browser support
The HTML-in-Canvas API is gated behind a browser flag. Feature-detect before relying on it:
Cast app.canvas to HTMLSourceCanvas for the typed requestPaint and captureElementImage members. source.requestPaint() returns false when the browser lacks the API; the texture uploader throws on first render when it is disabled.
When the API is missing the first upload throws [HTMLSource] WebGLRenderingContext.texElementImage2D is not available... on WebGL or [HTMLSource] GPUQueue.copyElementImageToTexture is not available... on WebGPU.
Live element with HTMLSource
The element must be a direct child of the renderer's <canvas>; the source infers the owning canvas from resource.parentElement (or pass canvas). With the defaults, it sets layoutsubtree on the canvas, listens for the canvas paint event, and requests one initial paint. source.isReady is false until that first paint lands, then true. It is true immediately when autoUpdate is false. resourceWidth/resourceHeight report the element's real-pixel size (offsetWidth/offsetHeight).
Continuous animation with requestPaint
The browser only repaints canvas children on demand. For an element whose content changes every frame, set autoRequestPaint: false and call source.requestPaint() in your own ticker to drive repaints on your schedule.
Immutable snapshot with ElementImageSource
captureElementImage() freezes an element's current pixels into an immutable ElementImage. There is no owning canvas, no paint listener, and no repaint lifecycle, so the source is ready the moment it is constructed. Reach for it when you need a frozen copy that outlives its element or is transferred around (transitions, "shatter" or trail effects). Release the snapshot with snapshot.close() when done, or pass autoClose: true to let the source close it on destroy().
Using the source on a sprite, texture, or mesh
Both sources are normal TextureSources. Wrap them with Sprite.from(source) / Texture.from(source), frame or slice them into sub-textures, or map them onto a mesh:
Auto-detection and priority
A generic HTML element or an ElementImage passed to Texture.from/Sprite.from resolves to these sources at the lowest texture-source priority (-10), so they only claim a resource no other built-in source handles. Image, video, and canvas elements are deliberately rejected; they have dedicated, faster sources. Construct the source explicitly when you need options (autoUpdate, autoClose) or non-HTML elements such as SVG.
Common Mistakes
[HIGH] Importing from pixi.js instead of pixi.js/html-source
Wrong:
Correct:
HTMLSource, ElementImageSource, and the 'html' uploaders live only in pixi.js/html-source. Importing anything from that path registers the extensions; the module is marked side-effectful, so bundlers keep the registration even when you only import a class.
[HIGH] Assuming the browser API is enabled
The HTML-in-Canvas proposal is not shipped by default. If the API is disabled, the uploader throws on first render. Feature-detect first:
[MEDIUM] Element not a direct child of the canvas
HTMLSource requires the element to be a direct child of the owning canvas (app.canvas.appendChild(form)) and throws otherwise. Append the element to the canvas before constructing the source, or pass the canvas option.
[MEDIUM] Expecting a live element to update without requestPaint
A non-animating element updates automatically on browser paint events (autoUpdate: true). Content that changes every frame will not re-upload unless something triggers a paint; drive it with source.requestPaint() each frame (with autoRequestPaint: false).
[MEDIUM] Closing an ElementImage still in use
Only set autoClose: true when the source owns the snapshot exclusively. For a shared snapshot, leave autoClose off and call snapshot.close() once, after the last source is destroyed.
Cleanup
HTMLSource.destroy() detaches the canvas paint listener and nulls its canvas reference. ElementImageSource.destroy() closes the snapshot when autoClose was set; otherwise call snapshot.close() yourself to release the memory.


