7. Head and body elements
Module 2 · About 20 minutes · Lesson 6; review earlier concepts as needed
Open Interactive LessonDiscover
What changes when you use head and body elements, and how can you prove it?
- Explain head and body elements using the example source
- Predict the visual or structural effect of one controlled change
- Repair the supplied fault and verify actual output
Predict
Record the expected structure or visual change before rendering. Name one thing that should remain unchanged.
Understand
The head contains metadata such as title and character encoding; the body contains the content users read and interact with. Putting visible content in head is invalid and may trigger browser repair. Inspect the actual tree to see where the browser placed it. Metadata does not replace a visible page heading. Use both a meaningful title and a clear h1.
Important source lines
- index.html:1 <!doctype html><html lang="en"><head><meta charset="utf-8"><title>Field notes</title></head><body><h1>Field notes</h1><p>Observations from the workshop.</p></body></html>
- The root of an HTML document, with its content language. Attribute guidance: lang="en".
The first example teaches this lesson’s primary contract. Additional examples are optional related references or applications, each with its own purpose and source; an example without an authored check requires the stated visual/manual review.
Example 1: Head and body elements
The title is metadata in head; the h1 is visible content in body.
index.html
<!doctype html><html lang="en"><head><meta charset="utf-8"><title>Field notes</title></head><body><h1>Field notes</h1><p>Observations from the workshop.</p></body></html>
styles.css
script.js
Expected: The title is metadata in head; the h1 is visible content in body.
Edit and Render This ExampleExample 2: Element: meta
Metadata such as character encoding, description or viewport configuration.
index.html
<!doctype html><html lang="en"><head><meta name="description" content="A concise page summary."><title>Metadata</title></head><body><h1>Metadata practice</h1></body></html>
styles.css
body { font:18px/1.6 system-ui; margin:1.5rem; color:#17324d; } img,video,svg { max-width:100%; height:auto; } th,td { padding:.5rem; border:1px solid #a8b8c8; } :focus-visible { outline:3px solid #a44322; outline-offset:3px; }script.js
Expected: Metadata such as character encoding, description or viewport configuration. Review its real DOM and native behavior; structural/media-only examples are labeled.
Edit and Render This ExampleExample 3: Element: title
The document title used in browser UI and navigation.
index.html
<!doctype html><html lang="en"><head><title>Specific page — Field Notes</title></head><body><h1>A title is not a body heading</h1></body></html>
styles.css
body { font:18px/1.6 system-ui; margin:1.5rem; color:#17324d; } img,video,svg { max-width:100%; height:auto; } th,td { padding:.5rem; border:1px solid #a8b8c8; } :focus-visible { outline:3px solid #a44322; outline-offset:3px; }script.js
Expected: The document title used in browser UI and navigation. Review its real DOM and native behavior; structural/media-only examples are labeled.
Edit and Render This ExampleExample 4: Element: h1
The highest-level heading for a page topic.
index.html
<h1>Workshop handbook</h1><p>A principal heading introduces the page.</p>
styles.css
body { font:18px/1.6 system-ui; margin:1.5rem; color:#17324d; } img,video,svg { max-width:100%; height:auto; } th,td { padding:.5rem; border:1px solid #a8b8c8; } :focus-visible { outline:3px solid #a44322; outline-offset:3px; }script.js
Expected: The highest-level heading for a page topic. Review its real DOM and native behavior; structural/media-only examples are labeled.
Edit and Render This ExampleExample 5: Element: p
A paragraph of prose.
index.html
<p>One idea belongs in a coherent paragraph.</p><p>A second paragraph develops another idea.</p>
styles.css
body { font:18px/1.6 system-ui; margin:1.5rem; color:#17324d; } img,video,svg { max-width:100%; height:auto; } th,td { padding:.5rem; border:1px solid #a8b8c8; } :focus-visible { outline:3px solid #a44322; outline-offset:3px; }script.js
Expected: A paragraph of prose. Review its real DOM and native behavior; structural/media-only examples are labeled.
Edit and Render This ExampleBuild and test
The title is metadata in head; the h1 is visible content in body. Repair the current exercise without removing necessary content. Checks inspect the stated structural/computed/stylesheet contract, not exact source text.
Starter index.html
<!doctype html><html lang="en"><head><meta charset="utf-8"></head><body><h1>Field notes</h1><p>Observations from the workshop.</p></body></html>
Starter styles.css
Objective contract
[
{
"type": "count",
"selector": "head title",
"value": 1,
"label": "Include 1 matching head title element(s)"
}
]Hint 1
Locate the first difference between the intended result and the real preview. Inspect matching elements and computed styles.
Hint 2
The relevant source uses <title>Field notes</title>. The exercise instead uses an omitted operation. Identify its effect before changing it.
Hint 3
Restore the intended <title>Field notes</title> operation or implement an equivalent structure/style. Run the actual checks and explain why it works.
Complete reference solution
index.html
<!doctype html><html lang="en"><head><meta charset="utf-8"><title>Field notes</title></head><body><h1>Field notes</h1><p>Observations from the workshop.</p></body></html>
styles.css
Explain, reflect and extend
Which part of the actual preview or inspector proves this result? Explain one boundary case and name what automated checks do not verify.
Apply this concept to a different realistic piece of content. Predict its structure or visual behavior, test narrow and wide widths where relevant, then record one invalid case and its repair.
Troubleshooting and professional practice
If nothing changes, confirm that you edited the active file and ran Run Preview, or enabled Auto Preview. Inspect the actual DOM because the browser may repair invalid nesting. For CSS, check selector matches, valid declarations, active queries and computed values. Preserve local asset paths and inspect warnings. The title is metadata in head; the h1 is visible content in body.
Knowledge check
Explain why the stated result follows from the source. Predict a second input or width and test it independently. Automated contracts and written explanations are reviewed separately.
Optional AI prompts
- Explain this lesson’s source line by line using the actual objective above.
- Help implement one small extension and define normal, boundary and failure tests.
- Review/debug the source against actual preview observations; verify standards and never claim rendering without evidence.