Learn/HTML, CSS & JS/3. Structuring a page
Lesson 3 of 8
Sign in

HTML, CSS & JS, lesson 3

Structuring a page

You could build a whole page out of <div>s, but HTML has semantic elements that say what each part is. Screen readers use them to let people jump around, search engines use them to understand content, and they make your own code easier to read.

The landmark elements

<header>
  <h1>Pancake Club</h1>
  <nav>
    <a href="/">Home</a>
    <a href="/recipes">Recipes</a>
  </nav>
</header>

<main>
  <article>
    <h2>Buttermilk pancakes</h2>
    <p>Tangy, tall and tender.</p>
  </article>
</main>

<footer>
  <p>Made with butter.</p>
</footer>
  • <header>: introductory content, usually the site name and navigation.
  • <nav>: a group of the main navigation links.
  • <main>: the main content. A page should have one <main>.
  • <section>: a themed part of the page, normally with its own heading.
  • <article>: something that would make sense on its own, like a blog post or a product card.
  • <footer>: closing information such as contact links or copyright.

When to use a div

<div> and its inline cousin <span> mean nothing on their own. They are useful when you need a box only for styling or scripting, with no meaning to add. Reach for a semantic element first, and fall back to <div> when none fits.

Further reading

  • MDN: Structuring documents
  • MDN: HTML elements reference

One exercise to try what you just read.

Exercise 1

Page landmarks

Turn this page into a properly structured one:

  • A <header> containing the <h1> and a <nav> with at least two links.
  • A <main> containing two <article> elements, each with an <h2>.
  • A <footer> with a paragraph.

Press Ctrl Enter or Check to test your code.