Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since November 2015.
The content property of the HTMLTemplateElement interface returns the <template> element's template contents as a DocumentFragment. This content's ownerDocument is a separate Document from the one that contains the <template> element itself — unless the containing document is itself constructed for the purpose of holding template content.
The Node.cloneNode() and Document.importNode() methods both create a copy of a node. The difference is that importNode() clones the node in the context of the calling document, whereas cloneNode() uses the document of the node being cloned. The document context determines the CustomElementRegistry for constructing any custom elements. For this reason, use document.importNode() to clone the content fragment so that custom element descendants are constructed using the definitions in the current document, rather than the separate document that owns the template content. See the Node.cloneNode() page's examples for more details.
For <template> elements created in the context of a normal HTML document, the ownerDocument of the content is a separate, freshly created document:
If the <template> element is created in the context of a document that itself was created for the purpose of holding template content, then the ownerDocument of the content is the same as that of the containing document:
| HTML # dom-template-content-dev |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Dec 1, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.