Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 6.1 — The Head in Depth
HTML · Example 1 of 3

A tour of the head

The script walks through every element in the head and prints its tag and its key attribute.

The head holds information about the page: how to decode it (charset), how to size it on phones (viewport), where relative links point (base), and which styles and scripts to load, and where you place each of them changes how the page behaves.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 6 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write a complete head for a page called Contact us — Green Leaf Café that sets UTF-8, the standard viewport, the title, a one-sentence description and a deferred script /js/contact.js.

02

A page has <base href="https://shop.example/en/">. What full URLs do cart, /help and ../fr/ resolve to?

Explain it without notes

01

Which elements are allowed in the head, and what happens if you put a <p> there?

02

What does width=device-width, initial-scale=1 do, and why should you never add user-scalable=no?

03

Why does a plain script in the head see null when it looks for an element in the body, and how do you fix it?

04

What does <base> do, and what is the surprising effect on #fragment links?

A tour of the head

Preview

Press Run to see the page.

Console

Nothing logged yet.

Expected console output

meta charset=utf-8
meta name=viewport
title Head tour
meta name=description
meta name=color-scheme
link rel=icon