Emmanuel Akinfulubi

HTML and CSSHTML and CSS

Use headings and paragraphs correctly in HTML

1 Headings and paragraphs, in order

easy

Mark up a short page with a title, two sections and prose. Use heading levels to describe the outline, not to pick a font size, and let CSS do the spacing.

Stuck? Three hints, smallest first
  1. 1. One <h1> per page. Everything below it steps down one level at a time.
  2. 2. Never skip a level to get a smaller heading. Change font-size in CSS instead.
  3. 3. <br> is not a spacing tool. Paragraph margins are.

index.html

<h1>Jibowu Park</h1>
<p>A working bus terminal on the Lagos mainland, and the busiest of the four.</p>

<h2>Getting there</h2>
<p>Six routes stop outside the gate. The walk from Yaba takes about twenty minutes.</p>

<h3>By bus</h3>
<p>Any vehicle marked for Oyingbo passes the entrance.</p>

<h2>Opening hours</h2>
<p>Ticketing opens at 05:00 and the last departure boards at 21:30.</p>

style.css

body {
  max-width: 62ch;          /* a readable measure, in characters */
  color: #17171a;
}

h1 { font-size: 1.6rem; margin: 0 0 0.4rem; }
h2 { font-size: 1.15rem; margin: 1.4rem 0 0.3rem; }
h3 { font-size: 1rem; margin: 1rem 0 0.3rem; }

p {
  margin: 0 0 0.8rem;       /* the gap between paragraphs, not a <br> */
  line-height: 1.6;
}
Rendered result. Shown, not machine-checked: there is no browser in the build.
8 checks that prove this answer

Assertions, run in the browser. The markup and styles above are handed to them as html and css, so press Run and each check prints ok. The build fails if a single one fails.

Checks for exercise 1

// Pull the heading levels out in document order, then look for a jump.
const levels = [...html.matchAll(/<h([1-6])\b/g)].map((m) => Number(m[1]));
const skips = levels.filter((l, i) => i > 0 && l - levels[i - 1] > 1);

test('the outline runs 1, 2, 3, 2', levels, [1, 2, 3, 2]);
test('no level is skipped', skips, []);
test('exactly one h1', countTag(html, 'h1'), 1);
test('four paragraphs carry the prose', countTag(html, 'p'), 4);
test('no br tags standing in for spacing', hasTag(html, 'br'), false);
test('the spacing is margin on the paragraph', /p\s*\{[^}]*margin/.test(css), true);
test('the measure is limited in ch, which tracks the font', /max-width\s*:\s*62ch/.test(css), true);
test('heading sizes are set in CSS, not chosen by level', /h2\s*\{[^}]*font-size/.test(css), true);

Output


      

Heading level is structure, not size. A screen reader user can list the headings and jump between them, so skipping from h2 to h4 to get smaller text puts a hole in the outline they navigate by. Set the size in CSS and the two concerns stay separate. The 62ch measure is the other habit worth taking: ch is the width of a “0” in the current font, so the line length stays readable when the font changes.

Newsletter

New writing, when it lands.

Occasional notes on shipping software with AI agents. No schedule, no filler, unsubscribe in one click.