Module lessons (1/4)
How Browsers Read HTML & The DOM Tree
What Happens When You Open a Web Page?
HTML (HyperText Markup Language) is not a programming language with loops or variables—it is a structural blueprint. When you visit a webpage, your browser downloads plain text and immediately converts nested tags like <body>, <h1>, and <p> into an in-memory tree called the DOM (Document Object Model).
Every element inside another element becomes a child node in that tree. CSS uses that tree to paint colors and arrange columns, while screen readers walk that exact same tree aloud for blind or low-vision visitors.
| HTML Piece | Purpose | Example |
|---|---|---|
| Opening & closing tag | Wraps content to define an element | <p>Hello</p> |
| Void element | Carries no children or closing tag | <img src="logo.png" alt="Logo" /> |
| Attribute | Adds configuration metadata | <html lang="en"> |
<!DOCTYPE html> | Tells the browser to use modern HTML5 rules | Top line of every .html file |
<head> | Invisible page metadata, title, and stylesheets | <title>Home</title> |
<body> | Visible headings, text, buttons, and media | <h1>Welcome</h1> |
Explore the DOM Tree Live
Switch between a valid component, a full document outline, and an accidentally unclosed heading tag to see how the browser builds—and repairs—the DOM tree:
Example 1 — Minimal Valid HTML5 Document
Notice that <title> lives inside <head> (it labels the browser tab and search results), while <h1> and <p> live inside <body> (where visitors see and read them).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Studio Portfolio</title>
</head>
<body>
<h1>Maya Lin — Product Designer</h1>
<p>Crafting accessible interfaces on the open web.</p>
</body>
</html>Example 2 — Proper Nesting (First Opened, Last Closed)
Tags must close in reverse order of how they opened, just like stacking Russian dolls:
<!-- Correct nesting: <em> closes before </p> -->
<p>Always close the <em>innermost tag</em> first.</p>
<!-- Broken overlap: triggers unpredictable browser auto-repair -->
<p>Never overlap <em>tags like</p> this.</em>Step 1 — Repair the broken HTML document skeleton
Complete the HTML5 document below with <!DOCTYPE html>, lang='en' on <html>, a non-empty <title> inside <head>, and an <h1> inside <body>.
Show hint
Add <!DOCTYPE html> on the first line, change lang="" to lang="en", put text inside <title>, and add an <h1> inside <body>.
Solution available after 3 attempts
Step 2 — Nest an accessible card cleanly
Wrap an <h2> heading and a <p> element containing a nested <strong> phrase inside an <article class='notice-card'> container.
Show hint
Rename the wrapper to <article class="notice-card"> and wrap "Sunday" inside <strong>Sunday</strong> inside the <p>.
Solution available after 3 attempts
Why do browsers enforce <!DOCTYPE html> at line 1 of an HTML document?
Suppose you inspect a page in DevTools and notice your <p> paragraph got swallowed inside an <h2> element. What most likely caused it?
<h2>Release Notes
<p>Everything shipped on time.</p>