document.importNode() is an instance method that copies a Node or DocumentFragment from another document so you can insert the copy into the current page later (see MDN Document: importNode()). Learn the deep flag, why parentNode stays null until insert, and how it differs from adoptNode() and cloneNode().
01
Kind
Instance method
02
Args
node, deep?
03
Returns
cloned node
04
Effect
Copies node
05
vs adopt
copy vs move
06
Status
Baseline
Fundamentals
Introduction
Nodes from an iframe, a parsed HTML document, a detached Document, or <template>.content belong to a different document than your main page ( ownerDocument.
MDN: importNode() creates a copy of that foreign node for the calling document. The imported node is not in the tree yet — you still call appendChild() or insertBefore() to show it.
💡
Import = copy. Adopt = move.
Unlike document.adoptNode(), importNode() does not remove the original from its source document. The result is a clone owned by the current document (MDN).
⚠️
Prefer importNode for other documents (MDN)
cloneNode() clones in the source document’s context. importNode() clones in the target document’s context (CustomElementRegistry). For HTMLTemplateElement.content and other foreign documents, MDN recommends document.importNode().
externalNode — the external Node or DocumentFragment to import into the current document (MDN).
deep Optional — boolean, default false. If true, externalNode and all descendants are copied. If false, only externalNode is imported — the new node has no children (MDN).
Return value
The copied importedNode in the scope of the importing document. Note: importedNode.parentNode is null until insertion (MDN).
Document.importNode() is Baseline Widely available on MDN (since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline Widely available
Document.importNode()
Copy a Node or DocumentFragment from another document into the current document context.
BaselineWidely available
Google Chrome1+
Yes
Mozilla Firefox4+
Yes
Apple SafariYes
Yes
Microsoft Edge12+
Yes
Opera9+
Yes
Internet Explorer9+
Yes
importNode()Wide
Bottom line: Use document.importNode(node, true) to deep-copy foreign nodes. Prefer adoptNode when you need to move instead of copy.
Wrap Up
Conclusion
document.importNode() is the Baseline way to copy a node from another document into your page’s document context. Remember the deep flag, insert the detached clone yourself, and choose adoptNode() when you need a move instead.
Copy foreign nodes into the current document context.
5
Core concepts
📝01
Copies
source stays
MDN
🔄02
deep
default false
MDN
🎯03
Detached
parentNode null
until insert
⚡04
vs adopt
copy vs move
MDN
🛡05
Status
Baseline
2015
❓ Frequently Asked Questions
MDN: Document.importNode() creates a copy of a Node or DocumentFragment from another document, to be inserted into the current document later. The original node stays in its source document.
No. MDN marks Document.importNode() as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
MDN: deep defaults to false. If true, externalNode and all descendants are copied. If false, only externalNode is imported — the new node has no children.
MDN: importedNode.parentNode is null because it has not yet been inserted into the document tree. Call appendChild or insertBefore to attach it.
importNode clones and leaves the original in place. adoptNode moves the original node out of the source document (MDN).
MDN: importNode clones in the context of the calling document; cloneNode uses the document of the node being cloned. That document context affects CustomElementRegistry for custom elements. Prefer importNode when cloning into another document (including template.content).
Did you know?
MDN highlights that <template>.content lives in a separate document. Using document.importNode(template.content, true) builds custom-element descendants with the current page’s definitions — a subtle but important reason to prefer importNode over a plain cloneNode for templates.