HTML template tag is used to store reusable HTML code fragments that are not rendered when the page loads.,Its content remains hidden on the client side and can be activated, cloned, and inserted into the document using JavaScript.
Stores HTML content that is not displayed immediately on the webpage.
Helps in reusing markup without duplicating code.
Content is rendered only when triggered using JavaScript.
Improves performance and keeps HTML structure clean and organized.
we have an unordered list of the courses that we have hidden to display using the <template> tag in HTML.
Syntax:
<template id="myTemplate"> <p>This is template content</p> </template>
Note: The <template> tag is new in HTML 5. This tag supports the global attributes in HTML.
[Approach1]: Using template tag content stays hidden until used
[Approach 2]: To illustrates the uses of JavaScript to display the template tag content.