HTML · Chapter 31 of 45

HTML Semantic Elements

Semantic elements clearly describe their meaning to both the browser and the developer, unlike generic <div> or <span> tags. Examples include <article>, <section>, <nav>, <aside>, <figure>, and <time>.

Using semantic HTML improves accessibility for screen reader users, helps search engines understand content better, and makes code easier to read and maintain for other developers.

Syntax
<article>...</article><section>...</section>

Common semantic tags

<article> is self-contained content (like a blog post), <section> groups thematically related content, <nav> holds navigation links, and <figure>/<figcaption> pair images with captions.

Benefits of semantics

Screen readers can navigate by landmarks (nav, main, header). Search engines weigh semantic structure when ranking and summarizing pages.

Example 1 (html)
<article>
  <h2>Blog Post Title</h2>
  <p>Post content...</p>
</article>
Output
Blog Post Title
Post content...

article marks this as a self-contained, independently distributable piece of content.

Example 2 (html)
<figure>
  <img src="chart.png" alt="Sales chart">
  <figcaption>Fig 1: Quarterly sales</figcaption>
</figure>
Output
(chart image)
Fig 1: Quarterly sales

figure and figcaption pair visual content with a caption semantically.

Key points

  • Semantic tags describe meaning, not just appearance.
  • <article>, <section>, <nav>, and <aside> are key structural tags.
  • <figure>/<figcaption> pair media with captions.
  • Semantics improve accessibility and SEO.
💡 Note: When in doubt, ask: 'does this content have inherent meaning?' If yes, prefer a semantic tag over a div.

📝 Quick Quiz

1. Which tag represents a self-contained piece of content like a blog post?

2. Which tag pairs an image with a caption?

3. Semantic HTML primarily improves: