Loading...

HTML essentialsFoundations

Semantic HTML

6 min lesson

Next
  • Semantic HTML means choosing tags that describe the meaning of content, like <nav> for navigation and <article> for a self-contained story.
  • It helps browsers, search engines and screen readers understand the page, not just how it looks.
  • Think of labeled boxes again: a box labeled 'kitchen' tells movers where it belongs, just as <nav> tells tools it is navigation.
  • Common semantic tags are header, nav, main, article, section, aside and footer.
  • A <div> is a generic container with no meaning; use it only when no semantic tag fits.
  • This builds on Comments, whitespace & HTML entities and the earlier structure lessons; now you pick meaningful tags instead of generic ones.
  • The example page has a header, nav, main article and footer; you will see them stacked as a simple page.
  • This finishes the Foundations group; you now have the structure, boxes and labels to build real pages.
Keep in mind
  • Choose the tag that matches the meaning, not the look.
  • Use one main per page and put navigation inside nav.
  • Reach for div only when no semantic element fits.
  • Semantic tags improve accessibility and search results for free.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Semantic HTML</title>
</head>
<body>
  <!-- The top area with the site name -->
  <header>
    <h1>My blog</h1>
  </header>
  <!-- The navigation links -->
  <nav>
    <a href="#">Home</a> | <a href="#">About</a>
  </nav>
  <!-- The main content of this page -->
  <main>
    <!-- A self-contained story -->
    <article>
      <h2>First post</h2>
      <p>This is a short article.</p>
    </article>
  </main>
  <!-- The bottom area with copyright -->
  <footer>
    <p>&copy; 2025 My blog</p>
  </footer>
</body>
</html>

What happens: A page with a header showing "My blog", a navigation row with "Home" and "About", a main area with the heading "First post" and the paragraph "This is a short article.", and a footer showing "© 2025 My blog".

Breaking it down

header

<header>...</header>

Marks the introductory area of a page or section, usually with a heading. It is not the same as <head>.

nav

<nav>...</nav>

Marks a block of navigation links. Screen readers can jump straight to it.

main

<main>...</main>

Marks the main content of the page. Use it once per page, and keep navigation and footers outside.

article

<article>...</article>

Marks a self-contained piece, like a blog post, that would make sense on its own.

footer

<footer>...</footer>

Marks the closing area of a page or section, often with copyright or contact info.

Semantic tags

TagMeaning
headerIntroductory area of a page or section
navA block of navigation links
mainThe main content, used once
articleA self-contained piece of content
sectionA themed group of content
asideContent related but not central
footerClosing area with extra info

A helpful analogy

Semantic tags are like labeled rooms in a house: kitchen, bedroom, bathroom. You could call every room 'room', but then nobody knows what happens inside. Semantic HTML gives each part of the page its proper room name.

Nesting rules

  • 1.Use only one main per page, and never put it inside header, nav, article or footer.
  • 2.A header or footer can appear inside an article to mark that article's own start and end.

Common mistakes

Using div for everything

Avoid

<div><div><a href="#">Home</a></div></div>

Use instead

<nav><a href="#">Home</a></nav>

A div says nothing about the content. Semantic tags tell browsers, search engines and screen readers what each part is.

Using header as the page head

Avoid

<header><title>My blog</title></header>

Use instead

<head><title>My blog</title></head>

head holds metadata and is not shown. header is a visible area at the top of the body. They are different tags.

Quick tips

  • •If you cannot decide between section and article, ask: could this stand alone? If yes, use article.
  • •Open the Elements panel: semantic tags show up as clearly named blocks, which makes debugging easier.
Previous
Next