HTML <template> tag

You are Here:

HTML <template> tag

The <template> tag holds the HTML content hidden from the browser.

The HTML content inside a <template> tag will not to be rendered immediately when a page is loaded.

The HTML content inside a <template> tag can be made visible and rendered later by using JavaScript.

Basic Example

In the following example, we will have the HTML content to be rendered later by using JavaScript.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <template> <h4>Apple</h4> <img src="/apple.png" alt="Apple"> </template> </body> </html>

Rendering Hidden HTML Content

In the following example, we will render the hidden HTML content inside a <template> tag by using JavaScript.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <template> <h2>Apple</h2> <img src="/apple.png" alt="Apple"> </template> <button onclick="renderContent()">Render Content</button> <script> function renderContent() { var getTag = document.getElementsByTagName("template")[0]; var cloneContent = getTag.content.cloneNode(true); document.body.appendChild(cloneContent); } </script> </body> </html>

Attributes

There is no special attributes for <template> tag. Only Global attributes.

Reminder

Hi Developers, we almost covered 99.5% of HTML Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in HTML.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author