C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
HTML <template> tagHTML <template> tag is used to hold the client-side content that will not render at the time of page load, but it can be instantiated during runtime using JavaScript. The content of the template will not be displayed until it is not activated using JavaScript. The browser processes the content of the <template> element while loading the page to ensure that the content is valid, the contents are not rendered, however. It can also be useful when you want to use same content multiple times in your HTML document without any change. The <template> tag can be placed anywhere inside of <head>, <body>, <frameset>, or <table> elements. The <template> tag is newly added element in HTML5. Syntax<template>.........</template> Following are some specifications about the HTML <template> tag
Example<!DOCTYPE html> <html> <head> <title>HTML Template tag</title> <style> body{ background-color: #e6e6fa; } </style> </head> <body> <h2>Example of template tag</h2> <button onclick="clickMe()">Click Me</button><br> <template id="mytemplate"> <img src="bird.jpg" alt="bird's image" height="100" width="100"> <script> alert("Thank you for choosing template. Click OK for image.") </script> </template> <script> function clickMe() { var x= document.getElementsByTagName("template")[0]; var clon = x.content.cloneNode(true); document.body.appendChild(clon);} </script> </body> </html> Output: Attribute:Tag-specific attributes:The <template> tag does not contain any specific attribute. Global attribute:The <template> tag supports the Global attributes in HTML. Supporting Browsers
Next TopicHTML textarea Tag
|