What are template literals in HTML using <template> tag?
Short answer: The <template> tag defines reusable HTML that isn’t rendered until you activate it via JavaScript.
Explain a bit more
Example: <template id="card-template"> <div class="card"> <h3></h3> <p></p> </div> </template> <script> const tmpl = document.getElementById("card-template"); clone.querySelector("p").textContent = "Use semantic tags for SEO."; document.body.appendChild(clone); </script> Key Takeaway: <template> = invisible HTML blueprint ready to be cloned dynamically.
Example code
const clone = tmpl.content.cloneNode(true);
clone.querySelector("h3").textContent = "HTML Tips";
Real-world example (ShopNest)
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png