liveBook · Manning

HTML template element

The HTML template element holds inert markup that can be cloned and inserted into a document.

How 3 Manning books explain it

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.

Read how Vanilla Web explains HTML template element →

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.

Read how Web Component Development with Modern Libraries and Tooling explains HTML template element →

What to know first

Related concepts

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.