Skip to content
KALANBLON
Show contents

Chapter 1 of 4 · 15 min

HTML: the structure of a page

By the end of this chapter, you'll be able to

  • Explain what an HTML tag and element are
  • Structure content with headings, paragraphs and lists
  • Add a link and an image with their attributes
  • Write a useful text alternative for an image

Tags around the content

HTML (HyperText Markup Language) isn't a programming language: it's a markup language. Each piece of content is surrounded by tags that say what it is:

<h1>Thieboudienne recipe</h1>
<p>A rice and fish dish from Senegal.</p>

<h1> opens the tag, </h1> closes it. The whole thing (opening tag, content, closing tag) forms an element. Tags indicate the meaning of the content, not its appearance: <h1> means "main heading", and it's CSS that will decide its size.

The most common elements:

ElementRole
<h1> to <h6>headings, from most to least important
<p>paragraph
<ul>, <ol>, <li>bulleted list, numbered list, list item
<a href="…">link to another page
<img src="…" alt="…">image (no closing tag)
<strong>, <em>important text, emphasised text

Attributes

An attribute gives more detail about an element. It's written in the opening tag: name="value". A link needs href (the destination), an image needs src (the file) and alt (the text alternative).

Line 7: a link. Its href attribute says where it goes.

Step 6 of 6
Text description of the animation
  1. The browser reads the file from top to bottom and creates an element for each tag.
  2. Line 1: a main heading. The browser displays it large by default.
  3. Line 2: a paragraph.
  4. Lines 3 and 4: a bulleted list starts, with a first item.
  5. Line 5: a second list item.
  6. Line 7: a link. Its href attribute says where it goes.

Your turn

Mini-lab: your first pageHTML · CSS

Preview

The preview is isolated from the page and runs no scripts · Ctrl/⌘ + Enter to run · Esc then Tab to leave the editor

Worked exercise

Worked exercise: a recipe card

Write the HTML of a recipe card with: a main heading, an introduction paragraph, a level 2 heading "Ingredients" followed by a bulleted list of three ingredients, and a level 2 heading "Steps" followed by a numbered list of two steps.

Hint 1
The bulleted list uses <ul>, the numbered list <ol>. In both cases, each item is an <li>.
Hint 2
Don't skip a heading level: after an <h1> come <h2>s.
Show the solution and common mistakes
<h1>Mango salad</h1>
<p>A fresh starter, ready in ten minutes.</p>

<h2>Ingredients</h2>
<ul>
  <li>2 mangoes</li>
  <li>1 lime</li>
  <li>A few mint leaves</li>
</ul>

<h2>Steps</h2>
<ol>
  <li>Dice the mangoes.</li>
  <li>Sprinkle with lime juice and mint.</li>
</ol>

Common mistakes:

  • Choosing a heading for its size (<h4> because it's "smaller"): headings express the content's hierarchy, size is set in CSS.
  • Forgetting to close a tag (</li>, </ul>): the browser often guesses, but not always the way you'd want.

Summary

  1. 1HTML describes the structure and meaning of a page with tags.
  2. 2An element = opening tag + content + closing tag.
  3. 3Attributes (href, src, alt…) give more detail about an element.
  4. 4Headings h1 to h6 form a hierarchy, without skipping levels.
  5. 5Every meaningful image needs a text alternative.

Your progress is saved on this device. Create a free account to keep your progress on all your devices.