Add a template element to your document with children defining your template (including optional `slot` elements to be used with the shadow DOM) and then, as needed, copy its `content` and apply.
The HTML template element can be used for content that is not rendered by default but can be instantiated during run-time. It can have <slot>
children which define a pattern for a resulting "flattened DOM tree" (when the template is added as the shadow DOM content of an element potentially with its own children). It is often used within Custom Elements and/or Shadow DOM, but this is not required.