Lesson 3: Semantic HTML: Headings, Links, Lists and Media
Semantic HTML means choosing tags that describe what content is, not just how it should look. A <nav> element says “this is navigation”, an <article> says “this is a self-contained piece of writing”, and a <footer> says “this is the end of the page”, and that meaning is useful to everyone except the human eye: screen readers announce it, search engines use it to understand the page, and other developers reading your code can see the structure at a glance. In the early days of the web, almost everything was built from generic <div> elements, which say nothing at all, and pages were harder to use and harder to maintain as a result. This lesson replaces the generic boxes with meaningful tags.
The landmarks of a page
Most pages share the same landmarks, and HTML gives each one a tag. The <header> holds the top of a page or a section, usually the site name and the main navigation. The <nav> element marks a group of links used for getting around the site. The <main> element wraps the central content of the page, and there should be exactly one of it, so assistive technology can jump straight to it. Inside the main content, <section> groups related content under a heading, and <article> marks a piece that could stand alone, such as a blog post or a news story. The <aside> holds content related to the main content but not part of it, such as a sidebar, and the <footer> closes the page with information such as copyright and contact links. Used together, these tags draw a map of the page that both people and machines can follow.
Links, lists and emphasis
Links are the heart of the web, and good links are written for humans. The text between the <a> tags should describe the destination, so write “Read the course catalogue” rather than “click here”, because a screen reader user may hear a list of links with no surrounding context, and “click here” tells them nothing. Lists come in three kinds: ordered lists (<ol>) for steps or rankings, unordered lists (<ul>) for groups with no order, and description lists (<dl>) for terms and definitions, and each list item sits in an <li> element. For emphasis, use <strong> for importance and <em> for stress, rather than <b> and <i>, because strong and em carry meaning while b and i only change the appearance. These small choices add up to pages that are easier to read, easier to navigate and easier to find.
<header>
<h1>Greenfield Library</h1>
<nav>
<a href="index.html">Home</a>
<a href="catalogue.html">Catalogue</a>
</nav>
</header>
<main>
<article>
<h2>New this month</h2>
<p>We have added <strong>forty</strong> new titles.</p>
<ul>
<li>Picture books</li>
<li>Poetry</li>
<li>Science</li>
</ul>
</article>
</main>
<footer>
<p>Open Monday to Saturday.</p>
</footer>
Images, audio and video
Images use the <img> element, which has no closing tag and two essential attributes: src, the address of the image file, and alt, a short text description of what the image shows. The alt text is read aloud by screen readers and shown if the image fails to load, so write it as if you were describing the image to someone who cannot see it, and leave it empty (alt="") only for purely decorative images. Audio and video use <audio> and <video> with the controls attribute, which gives the visitor play, pause and volume buttons, and you should always provide a text alternative, such as a transcript, for media that carries spoken words. Keep media files small, use formats browsers understand, such as JPEG or PNG for images, and never set a video to play automatically with sound, which is unpleasant for visitors and a problem for people using screen readers.
Putting the landmarks together
A well-structured page reads like a well-organised essay: a header that says where you are, navigation that says where you can go, one main area that says what this page is about, sections and articles that break the content into ideas, and a footer that closes things off. When you build pages this way, several good things happen at once: your CSS becomes simpler because you can style header, nav and main directly instead of inventing class names for every box, your pages work better with keyboards and screen readers, and search engines understand your content more accurately. From now on, before you write any HTML, sketch the structure on paper first: header, nav, main, sections, footer, and only then start typing. The habit takes a minute and saves hours of untangling later, and it is exactly how professional developers plan a page.
Key Terms
- Semantic HTML
- Using tags that describe what content is, such as nav, article and footer, rather than generic divs.
- Header
- The top of a page or section, usually holding the site name and navigation.
- Nav
- An element marking a group of links used for getting around a site.
- Main
- The element wrapping the central content of a page; there should be exactly one.
- Article
- A self-contained piece of content, such as a blog post, that could stand alone.
- Alt text
- A short description of an image, read by screen readers and shown if the image fails to load.
- Strong / em
- Elements that mark importance and stress, carrying meaning as well as appearance.
Discussion Questions
- If a div and a nav look identical on screen, why does it matter which one you use?
- Write two versions of a link: one that says “click here” and one that describes its destination. Which would a screen reader user prefer, and why?
- When should alt text be left empty, and when must it describe the image?
Practice Questions
- Which element should wrap the main content of a page, and how many of them should there be?
- Why is <strong> better than <b> for important text?
- What two attributes does every <img> element need?
- Which list type would you use for a recipe's steps, and why?
- Give one example of an <article> and one of a <section>.
Show answers
- The <main> element, and there should be exactly one. It lets assistive technology jump straight to the central content of the page.
- Strong carries meaning as well as appearance. A screen reader can announce strong text as important, while b only changes how it looks.
- src and alt. src gives the address of the image file, and alt gives a text description for screen readers and for when the image fails to load.
- An ordered list (<ol>). The steps must be followed in a particular order, and an ordered list numbers them and communicates that order.
- An article could be a single blog post; a section could be the “Latest news” area of a homepage. The article stands alone, while the section groups related content under a heading.