DOM Interfaces

HTMLTemplateElement

Represents inert template markup and exposes its contents through a DocumentFragment. The template's contents are not its ordinary child nodes. Import a copy into the target document before inserting it. Example result: Saved.

Formal Syntax & Structure

html syntaxhtml
const element = document.getElementById('demo'); // HTMLTemplateElement

Return Value

HTMLTemplateElement

An existing HTML DOM object associated with the template element in this example; this interface is a type, not a function return contract.

Working Example

Example Snippethtml
<template id="demo">  <p>Saved</p></template><p>  Result:  <output id="result"></output></p><script>  const e = document.getElementById('demo');  const result = value => { document.getElementById("result").textContent = String(value); };  result(e.content.firstElementChild.textContent);</script>
HTML Reference