coderef

<template>Baseline · Widely available

The &#x3C;template> HTML element holds HTML fragments which you can clone and insert into the document using JavaScript.

Supported in all major browsers for at least 30 months — safe to use without fallbacks. Baseline since Nov 12, 2015. Widely available since May 12, 2018.

Browser support

DesktopChrome
1–25Not supported
26+Supportedsince Mar 26, 2013
Current: 155
Edge
12–12Not supported
13+Supportedsince Nov 12, 2015
Current: 154
Firefox
1–21Not supported
22+Supportedsince Jun 25, 2013
Current: 157
Safari
1–7Not supported
8+Supportedsince Oct 16, 2014
Current: 27
MobileChrome Android
18–25Not supported
26+Supportedsince Apr 3, 2013
Current: 155
Firefox Android
4–21Not supported
22+Supportedsince Jun 25, 2013
Current: 157
Safari iOS
1–7Not supported
8+Supportedsince Sep 17, 2014
Current: 27

How to use

This feature is Baseline widely available — use it freely, no fallback needed.

Example

HTML
<template id="row">
  <tr><td class="name"></td><td class="email"></td></tr>
</template>

<script>
  const tpl = document.getElementById("row");
  const row = tpl.content.cloneNode(true);
  row.querySelector(".name").textContent = "Ada";
  document.querySelector("tbody").append(row);
</script>

Feature detection

JS · check before using
const el = document.createElement("template");
if (!(el instanceof HTMLUnknownElement)) {
  // <template> is supported
}

Sub-features

Support for each part of the feature (3). The overall table above shows when the whole feature works.

Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
HTMLTemplateElement261322826228
HTMLTemplateElement.content261322826228
template261322826228