Lab 14: Modern HTML Semantics

Time: 30 minutes | Level: Practitioner | Docker: docker run -it --rm node:20-alpine sh

Overview

Use HTML5 semantic elements correctly, implement JSON-LD structured data, add Open Graph/Twitter Card meta tags, and write accessible HTML that communicates meaning to browsers, search engines, and assistive technologies.


Step 1: HTML5 Semantic Elements

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Article Page</title>
</head>
<body>

  <!-- <header>: introductory content, navigation -->
  <header>
    <nav aria-label="Main navigation">
      <ul>
        <li><a href="/">Home</a></li>
        <li><a href="/about">About</a></li>
      </ul>
    </nav>
  </header>

  <!-- <main>: primary content (one per page) -->
  <main id="main-content">

    <!-- <article>: self-contained, redistributable content -->
    <article>
      <header>
        <h1>Article Title</h1>
        <p>By <address><a href="/author">Jane Doe</a></address></p>
        <!-- <time>: machine-readable datetime -->
        <time datetime="2024-03-15T14:30:00Z">March 15, 2024</time>
      </header>

      <!-- <section>: thematic grouping with heading -->
      <section aria-labelledby="intro-heading">
        <h2 id="intro-heading">Introduction</h2>
        <p>Content with <mark>highlighted term</mark> for context.</p>
      </section>

      <section>
        <h2>Details</h2>
        <!-- <details>/<summary>: disclosure widget -->
        <details>
          <summary>Show technical details</summary>
          <p>Hidden content revealed on click.</p>
        </details>

        <!-- <figure>/<figcaption> -->
        <figure>
          <img src="diagram.png" alt="System architecture diagram">
          <figcaption>Figure 1: System architecture overview</figcaption>
        </figure>
      </section>

      <!-- <aside>: tangential content -->
      <aside aria-label="Related links">
        <h3>See Also</h3>
        <ul>
          <li><a href="/related">Related Article</a></li>
        </ul>
      </aside>

    </article>
  </main>

  <!-- <footer>: authorship, copyright, links -->
  <footer>
    <p><small>&copy; 2024 My Site. All rights reserved.</small></p>
  </footer>

</body>
</html>

Step 2: Semantic Interactive Elements


Step 3: Semantic Text Elements


Step 4: Microdata


Step 5: JSON-LD Structured Data

JSON-LD is preferred — it doesn't require HTML modification:


Step 6: Open Graph & Twitter Cards


Step 7: Additional Head Meta


Step 8: Capstone — JSON-LD Schema Validator

📸 Verified Output:


Summary

Element
Purpose
SEO/A11y Impact

<article>

Self-contained content

Crawler context

<section>

Thematic grouping

Document outline

<aside>

Supplementary content

Skip in screen readers

<main>

Primary content

Landmark navigation

<dialog>

Native modal

Built-in a11y

<details>/<summary>

Disclosure widget

No JS needed

<time datetime>

Machine date

Search rich results

<mark>

Highlighted text

Emphasis in search

JSON-LD

Structured data

Rich results

Open Graph

Social preview

Click-through rates

canonical

Dedup URLs

SEO ranking

Last updated