Codectionary / Developer documentation / HTML

<template>

The <template> element holds HTML content that the browser parses but does not render or execute when the page loads. Its content is inert — scripts inside it will not run, and images inside it will not load — until it is cloned into the visible DOM via JavaScript. This makes it a clean way to define reusable markup fragments for dynamic UI without building HTML strings in JavaScript.

Syntax

<template id="my-template">
  <p>Reusable content</p>
</template>

Examples

Basic Template Definition

A template holding markup that stays hidden until cloned.

<template id="card-template">
  <div class="card">
    <h3></h3>
    <p></p>
  </div>
</template>

Cloning a Template with JavaScript

Using the template to generate repeated list items dynamically.

<template id="item-template">
  <li class="item"></li>
</template>
<ul id="list"></ul>

<script>
  const tpl = document.getElementById('item-template');
  const list = document.getElementById('list');
  ['HTML', 'CSS', 'JS'].forEach(text => {
    const clone = tpl.content.cloneNode(true);
    clone.querySelector('.item').textContent = text;
    list.appendChild(clone);
  });
</script>

Best practices

  • Use template for markup that will be cloned and reused multiple times via JavaScript, like list items or cards
  • Remember that content inside a template is inert — access it via the element's .content property, not by querying it directly
  • Prefer template over building HTML strings with string concatenation or innerHTML for repeated UI patterns
  • Combine with document.importNode or cloneNode(true) to insert a copy without mutating the original template

Browser compatibility

Support applies to the named feature, not every attribute or behaviour in this article. Versions refer to browsers, not operating systems.

<template>

Desktop

Chrome
Supported
From 26
Firefox
Supported
From 22
Safari
Supported
From 8
Edge
Supported
From 13
Opera
Supported
From 15

Mobile

Safari on iOS
Supported
From 8
Chrome for Android
Supported
From 26
Firefox for Android
Supported
From 22
Samsung Internet
Supported
From 1.5

MDN BCD record for this feature · MDN reference

Support history and limitations

Chrome

  • From 26

Firefox

  • From 22

Safari

  • From 8

Edge

  • From 13

Opera

  • From 15

Safari on iOS

  • From 8

Chrome for Android

  • From 26

Firefox for Android

  • From 22

Samsung Internet

  • From 1.5
HTMLTemplateElement.content

Desktop

Chrome
Supported
From 26
Firefox
Supported
From 22
Safari
Supported
From 8
Edge
Supported
From 13
Opera
Supported
From 15

Mobile

Safari on iOS
Supported
From 8
Chrome for Android
Supported
From 26
Firefox for Android
Supported
From 22
Samsung Internet
Supported
From 1.5

MDN BCD record for this feature · MDN reference

Support history and limitations

Chrome

  • From 26

Firefox

  • From 22

Safari

  • From 8

Edge

  • From 13

Opera

  • From 15

Safari on iOS

  • From 8

Chrome for Android

  • From 26

Firefox for Android

  • From 22

Samsung Internet

  • From 1.5
Node.cloneNode

Desktop

Chrome
Supported
From 1
Firefox
Supported
From 1
Safari
Supported
From 1.1
Edge
Supported
From 12
Opera
Supported
From 7

Mobile

Safari on iOS
Supported
From 1
Chrome for Android
Supported
From 18
Firefox for Android
Supported
From 4
Samsung Internet
Supported
From 1.0

MDN BCD record for this feature · MDN reference

Support history and limitations

Chrome

  • From 1

Firefox

  • From 1

Safari

  • From 1.1

Edge

  • From 12

Opera

  • From 7

Safari on iOS

  • From 1

Chrome for Android

  • From 18

Firefox for Android

  • From 4

Samsung Internet

  • From 1.0

MDN BCD 8.1.5 · Dataset built 2026-10-08 · Mapping reviewed 2026-10-21. These dates are not individual browser-test or claim-verification dates. Unknown means the data does not establish support.

HTML Living Standard

Specifications & further reading