<template>
Script and style
A fragment that is not rendered now but cloned later by script.
| How to write it | <template></template> |
|---|---|
| Closing tag | </template> |
| Void element | No — it must be closed |
| Common attributes | None in particular |
| Category | Script and style |
How to read this
- Most tags come in pairs, opening and closing. Only tags with no content — img, br — are left unclosed.
- Writing </br> for a void element does nothing useful; the browser ignores it or adds an empty line.
- Appearance is CSS’s job. A tag says what something is; bold or italic is only the consequence.
- Choosing the tag that matches the meaning helps search engines and screen readers alike. Wrapping everything in div throws that information away.
Frequently asked questions
Q. What is the HTML <template> tag?
A fragment that is not rendered now but cloned later by script.
Q. How do you write <template>?
As <template></template>. The opening <template> pairs with the closing </template>.
Q. Which attributes are common on <template>?
None in particular. The global attributes every element has — class, id, style — still apply.
Q. What group does <template> belong to?
The script and style group.