Nishaglobal Education logo

Page structure and semantic HTML

Organise a whole web page with semantic HTML: header, nav, main, section, article, aside and footer, plus div and span, and see the page as a tree of elements.

Lesson 4 of 1330 minQuiz: 4 questions

🎯 By the end of this lesson you will be able to:

  • Lay out a page with header, nav, main, section, article, aside and footer
  • Choose between a semantic element and a plain div or span
  • Read a page as a tree of parent and child elements
Outline
  1. What you'll learn and why it matters
  2. The main page regions
  3. Your page is a tree
  4. div and span: boxes with no meaning
  5. Practice
  6. Common mistakes
  7. Recap
  8. Quiz
  9. Mark lesson complete

What you'll learn and why it matters

So far your pages have been a list of headings and paragraphs. Real pages have regions: a header with the logo, a navigation menu, the main content and a footer. Semantic HTML means using elements whose names describe what the content *is*. Screen readers use them to let people jump straight to the menu or the main content, search engines use them to find what matters, and other developers can read your code much more easily.

The main page regions

ElementUse it forHow many
<header>The introduction: logo, site name, sometimes the menuUsually one for the page (sections can have their own)
<nav>The main links for moving around the siteOne or two
<main>The main content, different on every pageExactly one visible per page
<section>A themed group of content with its own headingAs many as needed
<article>Something that makes sense on its own: a blog post, a product card, a news storyAs many as needed
<aside>Related extras: a tip box, related linksOptional
<footer>Contact details, copyright, small printUsually one for the page
index.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Green Leaf Café</title>
</head>
<body>
  <header>
    <h1>Green Leaf Café</h1>
    <nav>
      <ul>
        <li><a href="index.html">Home</a></li>
        <li><a href="menu.html">Menu</a></li>
        <li><a href="contact.html">Contact</a></li>
      </ul>
    </nav>
  </header>

  <main>
    <section>
      <h2>Welcome</h2>
      <p>Fresh snacks and the best chai in town.</p>
    </section>
    <section>
      <h2>Today's specials</h2>
      <article>
        <h3>Banana bread</h3>
        <p>Baked every morning with local bananas.</p>
      </article>
      <article>
        <h3>Ginger lemon tea</h3>
        <p>Warm, spicy and caffeine-free.</p>
      </article>
    </section>
  </main>

  <footer>
    <p>12 Park Road, Pune · Open every day 8am to 8pm</p>
  </footer>
</body>
</html>

Browser preview

Without CSS this still looks like a plain document, and that is fine: structure first, style later. In Module 2 you will turn this into a proper-looking page.

Your page is a tree

Because elements sit inside each other, every page forms a tree. <html> is at the top, <head> and <body> are its children, and so on. The browser builds this tree, called the DOM (Document Object Model), from your HTML. CSS and JavaScript both work by finding elements in it.

htmlheadbodytitleheadermainfooterh1h2ppEach element sits inside its parent, like folders in folders.
The page as a tree: html contains head and body; head contains title; body contains header, main and footer; header contains h1, main contains h2 and p, footer contains p.

div and span: boxes with no meaning

Sometimes you need a box just to group things for styling, and no semantic element fits. Use <div> for a block (it starts on a new line) and <span> for a piece of text inside a line. They have no meaning of their own, so reach for them only after checking the semantic elements.

A div groups a card; a span marks a price
<div class="card">
  <h3>Masala chai</h3>
  <p>Price: <span class="price">₹40</span></p>
</div>

The class attribute gives an element a name you choose, so CSS can style it later. You will use classes a lot from lesson 7.

Practice

Guided exercise

Structure a blog page

Build a blog page with a header containing the blog name and a nav with two links, a main area with one article (title and two paragraphs), an aside with a tip, and a footer.

  1. Inside body, add <header> with an <h1> and a <nav> containing a <ul> of two links.
  2. Add <main> with one <article> holding an <h2> and two <p>.
  3. After the article, still inside main, add an <aside> with a short tip.
  4. Finish with <footer>.
Show the solution
Solution
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Ravi's Cooking Blog</title>
</head>
<body>
  <header>
    <h1>Ravi's Cooking Blog</h1>
    <nav>
      <ul>
        <li><a href="index.html">Home</a></li>
        <li><a href="recipes.html">All recipes</a></li>
      </ul>
    </nav>
  </header>
  <main>
    <article>
      <h2>The easiest dal you will ever make</h2>
      <p>You need just lentils, water, salt, turmeric and a little ghee.</p>
      <p>Boil the lentils until soft, then add a fried garlic and cumin tadka.</p>
    </article>
    <aside>
      <p>Tip: soak the lentils for 30 minutes to cook them faster.</p>
    </aside>
  </main>
  <footer>
    <p>Written by Ravi in Chennai.</p>
  </footer>
</body>
</html>

Browser preview

How to get there: The header and footer wrap the whole site's top and bottom, main holds this page's unique content, the post is an article because it makes sense on its own, and the tip is an aside because it is related but not essential.

Your turn

Replace the divs

The starter code uses only <div> elements. Rewrite it with the right semantic elements.

Starter code
<div>
  <h1>City Library</h1>
</div>
<div>
  <a href="books.html">Books</a>
  <a href="events.html">Events</a>
</div>
<div>
  <h2>Story time for children</h2>
  <p>Every Saturday at 11am.</p>
</div>
<div>
  <p>Call 020 1234 5678</p>
</div>
Show the solution
Solution
<header>
  <h1>City Library</h1>
</header>
<nav>
  <a href="books.html">Books</a>
  <a href="events.html">Events</a>
</nav>
<main>
  <h2>Story time for children</h2>
  <p>Every Saturday at 11am.</p>
</main>
<footer>
  <p>Call 020 1234 5678</p>
</footer>

Browser preview

How to get there: Each div becomes the element that describes its job: header for the top, nav for the menu, main for the page's own content and footer for contact details. The page looks the same, but now it has meaning.

Common mistakes

Building everything from <div>s

You see: The page works but screen readers cannot jump to the menu or main content

Fix: Use header, nav, main, section, article, aside and footer where they fit.

Using more than one <main>

You see: The validator reports an error and assistive tools get confused

Fix: Keep one main per page for the content unique to that page.

Using <section> without a heading

You see: A region with no name, which is hard to navigate

Fix: Give each section a heading, or use a div if it is only for styling.

Choosing an element for its look

You see: Odd structure, such as <aside> used just to make a narrow box

Fix: Pick elements for meaning; CSS controls the look.

Recap

  • Semantic elements describe what content is: header, nav, main, section, article, aside, footer.
  • Use exactly one main per page; give sections headings.
  • The browser turns your HTML into a tree (the DOM) of parents, children and siblings.
  • div and span are meaning-free boxes for styling; block elements start new lines, inline ones do not.

Key terms

Semantic HTML
HTML that uses elements whose names describe the content's meaning.
DOM
Document Object Model: the tree of elements the browser builds from your HTML.
Landmark
A major page region, such as nav or main, that assistive technology can jump to.

Check your understanding

Answer all 4 questions, then check your answers to see an explanation for each one.

  1. 1. Which element should hold the site's main menu links?

  2. 2. A news site lists five stories, each with a title, picture and summary that make sense on their own. Which element suits each story?

  3. 3. How many visible main elements should a page have?

  4. 4. In `<ul><li>A</li><li>B</li></ul>`, what are the two li elements to each other?

Answer all 4 questions to check.

Mark this lesson complete

Finished this lesson?

When you have worked through the examples and exercises, mark it complete to save your progress.