Codectionary / Developer documentation / HTML

HTML template Element

The template element holds inert document fragments. Its contents are not rendered until JavaScript clones and inserts them into the document.

Syntax

<template id="item-template">...</template>

Examples

Cloning a template

A small, runnable example of this syntax.

<template id="message-template">
  <p class="message"></p>
</template>
<div id="messages"></div>
<script>
  const fragment = document.querySelector("#message-template").content.cloneNode(true);
  fragment.querySelector(".message").textContent = "Saved";
  document.querySelector("#messages").append(fragment);
</script>

Best practices

  • Use templates for repeated DOM structures and fill them with safe textContent rather than untrusted HTML.
  • Keep examples small while learning, then combine the idea with a real project.

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