HTML template element
The HTML template element holds inert markup that can be cloned and inserted into a document.
Web Components in Action
The HTML template element is an HTML element that holds inert markup which can be instantiated as a document fragment.
- How it is used
- Keeps reusable HTML and CSS layouts as HTML for Web Components instead of storing all markup in JavaScript strings.
- How deep it goes
- Explains inert content and document fragments, then works through cloning, layout switching, and remote loading.
- Examples
- Uses button, text-field, and list templates, followed by a business card with selectable layouts.
- What you can do after
- Build it from scratch: clone template content to populate a custom element and swap layouts when its attribute changes.
Read how Web Components in Action explains HTML template element →
Vanilla Web
The HTML <template> element holds inert markup that can later be cloned and inserted into a document or shadow DOM.
- How it is used
- Provides reusable, inert markup for repeated DOM structures and custom-element instances.
- How deep it goes
- Works through declaration, DocumentFragment ownership, cloning, insertion, and dynamic filling; treats template engines as optional.
- Examples
- Uses cloned product-table rows, product cards, cart items, and a product-list renderer.
- What you can do after
- Build it from scratch with native DOM APIs: clone a shared fragment, fill its nodes, and insert each instance.
Web Component Development with Modern Libraries and Tooling
An HTML element containing reusable markup that is not rendered until its contents are cloned into a document.
- How it is used
- Supplies reusable markup for rendering instances of vanilla web components into their shadow roots.
- How deep it goes
- Works through template creation, HTML assignment, cloning, and shadow-root insertion, including a populated radio-group render method.
- Examples
- Uses a radio-group template with a fieldset and slots, plus a sortable-table template with table headings and a body.
- What you can do after
- Build it from scratch by cloning template content, populating the copy, and placing it in a component’s shadow root.
What to know first
- accessor methodAn accessor method or function is a callable that reads, computes, or assigns a value associated with a property, field, or data element.
- CSSCSS (Cascading Style Sheets) is a stylesheet language for specifying the presentation and layout of structured documents.
- Document Object ModelThe Document Object Model is a platform-independent programming interface that represents a document as a structured tree of nodes and provides ways to access and modify its content and structure.
- handlerA handler is a software routine or component invoked to process an event, request, message, or other input.
Related concepts
- DOM fragmentuses · A DOM fragment is a lightweight, detached node that can hold a subtree of nodes independently of a document tree.
- Custom Elementsuses · A custom element is an author-defined HTML element that represents application-specific content or behavior beyond that of built-in HTML elements.
- declarative shadow rootcontrasts with · A declarative shadow root is a shadow DOM tree specified in HTML markup and attached by the browser during parsing.
- template content propertyuses · The template content property returns an HTML template element’s stored contents as a DocumentFragment.
- template engineused by · A template engine is software that combines reusable templates with data and rules to generate rendered output such as text, documents, or user-interface views.
- Web Componentspart of · Web Components are browser standards and APIs, including custom elements and shadow DOM, for creating reusable web interface elements with encapsulated structure, presentation, and behavior.
Questions about HTML template element
What is HTML template element?
The HTML template element holds inert markup that can be cloned and inserted into a document.
Which Manning books explain HTML template element?
Web Components in Action, Vanilla Web and Web Component Development with Modern Libraries and Tooling.
What should I know before learning HTML template element?
Manning books that teach HTML template element usually introduce accessor method, CSS, Document Object Model and handler first.
What is the difference between HTML template element and declarative shadow root?
The HTML template element holds inert markup that can be cloned and inserted into a document. A declarative shadow root is a shadow DOM tree specified in HTML markup and attached by the browser during parsing.
What is HTML template element part of?
HTML template element is part of Web Components. Web Components are browser standards and APIs, including custom elements and shadow DOM, for creating reusable web interface elements with encapsulated structure, presentation, and behavior.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


