document.mozSetImageElement() is a Non-standard instance method that overrides which element backs a CSS -moz-element(#id) background (see MDN Document: mozSetImageElement()). Learn the MDN canvas click demo, how to clear with null, and safer cross-browser alternatives.
01
Kind
Instance method
02
Args
id, element
03
Returns
undefined
04
CSS
-moz-element()
05
Engine
Firefox
06
Status
Non-standard
Fundamentals
Introduction
Firefox can paint one element as another’s CSS background using background-image: -moz-element(#some-id). Normally that ID points at a real element in the page.
MDN: mozSetImageElement(imageElementId, imageElement) changes the element used for that background ID — even to a detached <canvas> you just created. Pass null to remove the override.
💡
Think: “Swap the live background source for this ID”
1) CSS: background-image: -moz-element(#canvas-bg); 2) Build a canvas (or other element) 3) document.mozSetImageElement("canvas-bg", canvas) 4) Or clear with ..., null) (MDN)
⚠️
Learning only — not for production
MDN recommends against non-standard features in production. Chrome, Safari, and Edge will simply ignore this API. Always feature-detect and keep a standard background path.
Document.mozSetImageElement() is Non-standard on MDN and works in Firefox (4+). Other major engines do not implement it. Logos use the shared browser-image-sprite.png sprite from this project.
✓ Non-standard ยท Firefox
Document.mozSetImageElement()
Override which element backs a -moz-element() CSS background ID. Feature-detect and prefer standard backgrounds.
FirefoxNon-standard
Mozilla Firefox4+
Yes
Google ChromeNot supported
No
Microsoft EdgeNot supported
No
Apple SafariNot supported
No
OperaNot supported
No
Internet ExplorerNot supported
No
mozSetImageElement()Narrow
Bottom line: Use only for Firefox experiments or legacy literacy. Ship standard CSS background fallbacks for every other browser.
Wrap Up
Conclusion
document.mozSetImageElement() is a Firefox-only, Non-standard way to point a -moz-element() background ID at a different element (often a canvas). Learn the MDN pattern for literacy, then ship standard background-image techniques for real apps.
Five things to remember about mozSetImageElement()
Non-standard Firefox background-element override.
5
Core concepts
📝01
Returns
undefined
MDN
🔄02
CSS
-moz-element
pair
🎯03
null
clears
MDN
⚡04
Engine
Firefox
4+
🛡05
Status
Non-std
MDN
❓ Frequently Asked Questions
MDN: Document.mozSetImageElement() changes the element used as the CSS background for a background that uses a given background element ID with the -moz-element() CSS function.
MDN marks Document.mozSetImageElement() as Non-standard. It is not part of any specification. It is not marked Deprecated or Experimental on MDN, but you should not use it in production.
Firefox only (from Firefox 4+). Chrome, Safari, Edge, Opera, and IE do not support it.
None (undefined) (MDN).
MDN: pass null as imageElement to remove the background element override for that ID.
Prefer standard CSS backgrounds: url(), gradients, canvas.toDataURL() / drawImage, or SVG patterns. Avoid depending on -moz-element() and mozSetImageElement() for cross-browser apps.
Did you know?
The MDN canvas demo never appends the canvas to the document — mozSetImageElement can still use that detached canvas as the painted background source for -moz-element(#canvas-bg).