Skip to main content
Module 1 · Lesson 1 of 41/60 in the course~15 min
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 PiecePurposeExample
Opening & closing tagWraps content to define an element<p>Hello</p>
Void elementCarries no children or closing tag<img src="logo.png" alt="Logo" />
AttributeAdds configuration metadata<html lang="en">
<!DOCTYPE html>Tells the browser to use modern HTML5 rulesTop 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).

HTML
<!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:

HTML
<!-- 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>
Practice Stage

Step 1 — Repair the broken HTML document skeleton

Exercise#html-css.m1.l1.e1
Attempts: 0Loading…

Complete the HTML5 document below with <!DOCTYPE html>, lang='en' on <html>, a non-empty <title> inside <head>, and an <h1> inside <body>.

Loading editor…
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

Practice Stage

Step 2 — Nest an accessible card cleanly

Exercise#html-css.m1.l1.e2
Attempts: 0Loading…

Wrap an <h2> heading and a <p> element containing a nested <strong> phrase inside an <article class='notice-card'> container.

Loading editor…
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

HTML & CSS Quiz#html-css.m1.l1.e3
Ready

Why do browsers enforce <!DOCTYPE html> at line 1 of an HTML document?

Answer options
HTML & CSS Quiz#html-css.m1.l1.e4
Ready

Suppose you inspect a page in DevTools and notice your <p> paragraph got swallowed inside an <h2> element. What most likely caused it?

HTML
<h2>Release Notes
<p>Everything shipped on time.</p>
Answer options