Skip to main content
InterviewHubPRO
Section Overview
Q19

Question 19 of 50

Part 2: Core Architecture & Implementation (Mid-Level)

38%
HTML5 & Web APIs (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)

What is the `<template>` element?

senior LevelCode ExampleComponentsSystem Design

In Simple Words: The <template> tag holds client-side HTML markup that is parsed but not rendered on page load:

html
<template id="comment-template">
  <div class="comment">
    <strong class="author"></strong>
    <p class="body"></p>
  </div>
</template>
  • Its contents do not execute scripts, load images, or apply styles until cloned into the live DOM using JavaScript:
    javascript
    const template = document.getElementById('comment-template');
    const clone = template.content.cloneNode(true); // Deep clone
    clone.querySelector('.author').textContent = 'Alice';
    document.getElementById('comments-list').appendChild(clone);