Semantic HTML

Give meaning to your web structure for better SEO, accessibility, and maintainability.

Page Structure

HTML5 introduced specific tags to define page layout clearly instead of using div for everything.

  • <header> : Introductory content or navigation links.
  • <nav> : Major block of navigation links.
  • <main> : The unique central content of the page.
  • <footer> : Author info, copyright, or contact details.

Page Layout Structure

Using header, nav, main, article, aside and footer to structure a page.

Defining Content Blocks

These tags break your main content into logical pieces that search engines and screen readers understand.

  • <section> : A thematic grouping of content with a heading.
  • <article> : Self-contained content that could stand alone (blog post, news story).
  • <aside> : Content related to but not part of the main flow, like a sidebar.

Sections Inside Main

Use section to group related content into separate thematic blocks.

Media & Interaction

Semantic tags also cover media grouping and native interactive widgets.

  • <figure> : Groups an image or diagram with its caption.
  • <figcaption> : The caption for a figure element.
  • <details> : A native expand/collapse widget.
  • <summary> : The always-visible heading inside details.

Figure and Figcaption

Wrapping an image with figure and adding a caption using figcaption.

Details and Summary

Creating native expand/collapse widgets with no JavaScript required.

Knowledge Check

1. Which element should contain the primary, non-repeated content of a page?

2. What is the benefit of using semantic tags over generic <div> tags?

3. Which tag is used to create a sidebar or content indirectly related to the main text?

4. Which element provides a visible heading for the <details> element?