HTML Dog
Skip to navigation

HTML Tag: template

A block of HTML that can be cloned and inserted with JavaScript.

The static template element itself is not considered part of the document and exists only to be manipulated by a script.

Optional Attributes

Global attributes

Example


<h3>Optional Attributes</h3>

<table>

    <tr>
        <th>Attribute</th>
        <th>Description</th>
        <th>Possible values</th>
    </tr>

    <template id="row">
        <tr>
            <td></td>
            <td></td>
            <td></td>
        </tr>
    </template>

</table>

<script>
var template = document.querySelector('#row');
for (var i = 0; i < 4; i += 1) {
    var clone = template.content.cloneNode(true);
    // data-filling gubbins
    template.parentNode.appendChild(clone);
}
</script>