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:
| Element | Role |
|---|---|
<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.
Text description of the animation
- The browser reads the file from top to bottom and creates an element for each tag.
- Line 1: a main heading. The browser displays it large by default.
- Line 2: a paragraph.
- Lines 3 and 4: a bulleted list starts, with a first item.
- Line 5: a second list item.
- 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
<ul>, the numbered list <ol>. In both cases, each item is an <li>.Hint 2
<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
- 1HTML describes the structure and meaning of a page with tags.
- 2An element = opening tag + content + closing tag.
- 3Attributes (href, src, alt…) give more detail about an element.
- 4Headings h1 to h6 form a hierarchy, without skipping levels.
- 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.