×

html · level 3 · unit 6 · lesson 4

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

keeps HTML ready to copy, but never shows it.

A template is like a stencil: you keep it ready and stamp out copies. In HTML it is <template>. Everything inside is : not shown, not read out by screen readers, and its pictures are not even downloaded.

On its own, a template does nothing. A script, which you will meet in JavaScript, copies it to add new cards, rows or messages, each one built the same way.

That makes it a tidy home for spare parts: a product card ready to repeat, or a message kept for later.

<h2>Our cakes</h2>
<ul id="cakes">
  <li>Lemon drizzle, £3</li>
</ul>
<template id="cake-card">
  <li>
    <img src="cake.svg" alt="A slice of cake" width="80" height="80">
    <span>New cake</span>
  </li>
</template>

Press show my page to see it here.

The cake picture in the template is not downloaded until a copy is placed on the page.