Fullstack CourseLearn by building
Back to week 1

Topic

HTML document structure

Definition

An HTML document is a tree of elements that starts with a doctype and an html root, contains machine-readable metadata in head, and visible page content in body, preferably marked with semantic landmark and content elements.

In simpler words

HTML is the page skeleton: head holds title and links to CSS; body holds what people see. Prefer meaningful tags (header, main, nav) over a pile of anonymous divs.

Document outline, semantic landmarks, headings, lists, links, and basic form controls so you can read markup before JSX.

After this you can

  • Sketch a valid document with head/body landmarks and choose semantic tags for a simple page layout.
  • Explain the trade-off to a teammate using a small example.
  • Name at least one common bug pattern for this topic.

Understand HTML document structure

Document outline, semantic landmarks, headings, lists, links, and basic form controls so you can read markup before JSX.

Start by identifying which value or browser behavior changes. Then describe the UI from that current input instead of editing the DOM as a separate source of truth.

HTML document structure in code

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>Tickets</title>
    <link rel="stylesheet" href="styles.css" />
  </head>
  <body>
    <header>
      <nav aria-label="Primary">
        <a href="/">Home</a>
      </nav>
    </header>
    <main>
      <h1>Open tickets</h1>
      <article>
        <h2>Cookie auth on web</h2>
        <p>Login with credentials and hit /auth/me.</p>
      </article>
    </main>
  </body>
</html>

Read the example from data and control flow to the resulting UI. Keep the component boundary small.

Apply HTML document structure

Keep rendering as a calculation. Put user-triggered changes in event handlers, preserve UI memory in state, and reserve external synchronization for Effects or the server-state layer.

Name values by their UI meaning, test the loading and error path when data is remote, and avoid keeping two editable copies of the same value.

Ask before adding code: is this local UI memory, shared client state, or Nest-owned server state?

Where bugs hide

Definition

High-bug areas are places where a small API misuse looks correct but produces stale UI, duplicate work, or silent failures.

In simpler words

Each mistake below shows Wrong vs Right code — compare them side by side.

When something misbehaves, match the symptom to a pattern below before rewriting the feature.

Prefer fixing the ownership or update path over adding another Effect or sync step.

Mistake: Skipping the document outline

// Wrong
<div>
  <div>Tickets</div>
  <div>Open tickets</div>
</div>

// Right
<main>
  <h1>Tickets</h1>
  <section>
    <h2>Open tickets</h2>
  </section>
</main>

Headings and landmarks give assistive tech and browsers a map. Divs alone do not.

Mistake: Putting visible content only in head

// Wrong
<head>
  <h1>Dashboard</h1>
</head>

// Right
<head>
  <title>Dashboard</title>
</head>
<body>
  <h1>Dashboard</h1>
</body>

Visible content belongs in body. head is for metadata and resources.

Mistake: Using a for everything

// Wrong
<a onclick="deleteTicket()">Delete</a>

// Right
<button type="button">Delete</button>
<a href="/tickets/42">View ticket</a>

Links navigate. Buttons trigger actions. Mixing them breaks keyboard and accessibility expectations.

Live playground

HTML document structure sandbox

Change one input at a time and predict the next render.

No interactive demo for course-html-document-structure yet — use the code samples and Wrong vs Right examples above.

Keep in mind

  • Keep the formal definition in mind; it explains which tool belongs where.
  • Prefer one source of truth over synchronized copies of the same value.
  • When behavior surprises you, trace: input → update → render → committed UI.
  • Study the Wrong vs Right examples in “Where bugs hide” before you merge.

Test

Check your understanding

At least 10 questions — mix of concept, syntax, practical, and logic. Score ≥ 80% (enforced by the API) to save progress.

Checking your session…

10 questions · concept 3 · syntax 3 · practical 2 · logic 2

Concept1. What is the role of the HTML document tree?
Syntax2. Which snippet is a valid minimal document skeleton?
Practical3. You need a page landmark for the primary content. Which element is appropriate?
Logic4. Why prefer <h1> then <h2> over multiple <div> titles?
Concept5. What belongs in <head>?
Syntax6. Which markup correctly links to another page?
Practical7. For a site-wide navigation list, which pattern is best?
Logic8. A delete control should not navigate away. What should you use?
Concept9. What does a semantic landmark element provide?
Syntax10. Which form control pair is correctly associated?