CodeBlanks Logo Icon CodeBlanks

Summary - Card template

HTML course · Advanced · Lesson 40/56

Write a reusable card template with template and slot.

Card template summary

This group taught you four building blocks: <template> for the skeleton, <slot> for content, custom element naming for the component, and shadowrootmode for declarative shadow DOM. Together they form a reusable card.

The right card template works like this: template prepares the skeleton, slot receives outside content, the custom element name calls the card, shadow DOM shields the inner structure. These four are the base of modern reusable components.

Exercise Write a reusable card template

Add a <template> to body. Inside it put an <article>. Inside the article put an <h2> (text: Title) and a <slot> (fallback: No content).

Show example solution
<body>
  <template>
    <article>
      <h2>Title</h2>
      <slot>No content</slot>
    </article>
  </template>
</body>

Test yourself

  1. Which is the correct card skeleton?

    • <div><h2>Title</h2></div>
    • <template><h2><slot></slot></h2><slot></slot></template>
    • <template><h2>Title</h2><p>Content</p></template>
    • <slot><template><h2>Title</h2></template></slot>
    Show answer

    <template><h2><slot></slot></h2><slot></slot></template> — Correct. A template with an h2 and a slot is the right card skeleton.

  2. Write the card title

    <template>
      <article>
        <h2>____</h2>
        <slot></slot>
      </article>
    </template>
    Show answer
    <template>
      <article>
        <h2>Title</h2>
        <slot></slot>
      </article>
    </template>
  3. Match the card template concepts

    template
    skeleton template
    slot
    content insertion point
    custom element
    component name
    shadowrootmode
    shadow DOM mode

All lessons in Advanced