Back to Content

HTMLTemplateElement

files/en-us/web/api/htmltemplateelement/index.md

latest2.6 KB
Original Source

{{APIRef("Web Components")}}

The HTMLTemplateElement interface enables access to the contents of an HTML {{HTMLElement("template")}} element.

[!NOTE] An HTML parser can create either an HTMLTemplateElement or a {{domxref("ShadowRoot")}} when it parses a {{HTMLElement("template")}} element, depending on the <template> attributes. If an HTMLTemplateElement is created the "shadow" attributes are reflected from the template. However these are not useful, because an HTMLTemplateElement is not a shadow root and cannot subsequently be changed to a shadow root.

{{InheritanceDiagram}}

Instance properties

This interface inherits the properties of {{domxref("HTMLElement")}}.

  • {{domxref("HTMLTemplateElement.content", "content")}} {{ReadOnlyInline}}
    • : A read-only {{domxref("DocumentFragment")}} which contains the DOM subtree representing the {{HTMLElement("template")}} element's template contents.
  • {{domxref("HTMLTemplateElement.shadowRootMode", "shadowRootMode")}}
    • : A string that reflects the value of the shadowrootmode attribute of the associated <template> element.
  • {{domxref("HTMLTemplateElement.shadowRootDelegatesFocus", "shadowRootDelegatesFocus")}}
  • {{domxref("HTMLTemplateElement.shadowRootClonable", "shadowRootClonable")}}
    • : A boolean that reflects the value of the shadowrootclonable attribute of the associated <template> element.
  • {{domxref("HTMLTemplateElement.shadowRootCustomElementRegistry", "shadowRootCustomElementRegistry")}}
    • : A string that reflects the value of the shadowrootcustomelementregistry attribute of the associated <template> element, indicating that the declarative shadow root will use a scoped {{domxref("CustomElementRegistry")}}.
  • {{domxref("HTMLTemplateElement.shadowRootSerializable", "shadowRootSerializable")}}
    • : A boolean that reflects the value of the shadowrootserializable attribute of the associated <template> element.

Instance methods

This interface inherits the methods of {{domxref("HTMLElement")}}.

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}