TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

HTML template tag

HTML template tag with examples, html5, forms, input, text, anchor, image, heading, marquee, textarea, paragraph, title, quotes, code etc.

<< Back to HTML

HTML <template> tag

HTML <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

Display None
Start tag/End tag Start and End tag
Usage Formatting

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>
Test it Now

Output:

HTML template tag

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

Elementchrome browser Chromeie browser IEfirefox browser Firefoxopera browser Operasafari browser Safari
<template>YesNoYesYesYes
Next TopicHTML textarea Tag




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf