Skip to content

Commit 06f99af

Browse files
authored
Clarify <template> permitted content (mdn#40458)
1 parent 7fdf197 commit 06f99af

File tree

1 file changed

+5
-1
lines changed
  • files/en-us/web/html/reference/elements/template

1 file changed

+5
-1
lines changed

files/en-us/web/html/reference/elements/template/index.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ This element includes the [global attributes](/en-US/docs/Web/HTML/Reference/Glo
4545

4646
## Usage notes
4747

48+
This element has no permitted content, because everything nested inside it in the HTML source does not actually become the children of the `<template>` element. The {{domxref("Node.childNodes")}} property of the `<template>` element is always empty, and you can only access said nested content via the special {{domxref("HTMLTemplateElement.content", "content")}} property. However, if you call {{domxref("Node.appendChild()")}} or similar methods on the `<template>` element, then you would be inserting children into the `<template>` element itself, which is a violation of its content model and does not actually update the {{domxref("DocumentFragment")}} returned by the `content` property.
49+
50+
Due to the way the `<template>` element is parsed, all `<html>`, `<head>`, and `<body>` opening and closing tags inside the template are syntax errors and are ignored by the parser, so `<template><head><title>Test</title></head></template>` is the same as `<template><title>Test</title></template>`.
51+
4852
There are two main ways to use the `<template>` element.
4953

5054
### Template document fragment
@@ -319,7 +323,7 @@ Since `firstClone` is a `DocumentFragment`, only its children are added to `cont
319323
</tr>
320324
<tr>
321325
<th scope="row">Permitted content</th>
322-
<td>No restrictions</td>
326+
<td>Nothing (see <a href="#usage_notes">Usage notes</a>)</td>
323327
</tr>
324328
<tr>
325329
<th scope="row">Tag omission</th>

0 commit comments

Comments
 (0)