HTML Tutorial

Semantic Elements

Giving meaning to your code for SEO and Accessibility

What is Semantics?

In HTML, a Semantic element clearly describes its meaning to both the browser and the developer. Using <div> for everything is "Non-semantic" because a div tells you nothing about its content.

Why use Semantic HTML?

  1. SEO: Search engines (like Google) can understand your page much better.
  2. Accessibility: Screen readers for blind users rely on these tags to navigate the page.
  3. Maintainability: Your code is much easier to read and organize.

Core Semantic Tags

TagPurpose
<header>Introduction or navigation links
<nav>A block of navigation links
<main>The unique, central content of the page
<section>A standalone section of a document
<article>A self-contained piece of content (like a blog post)
<aside>Content related to the main, but not essential (sidebar)
<footer>Information about the author, copyright, or contact info

The "Div" Habit

Wait! It's easy to fall into the habit of using <div> for everything. A div is just a "container" with no meaning. Only use a <div> when there is no semantic tag that fits.

Summary

TermDescription
SemanticMeaningful tag names
SEOSearch Engine Optimization
A11yShort for Accessibility
SectionA thematic grouping of content
ArticleIndependent, reusable content
Best ForBuilding high-quality, accessible, and searchable websites
Logic"Describe WHAT the content is, not just HOW it looks"
SafetySemantic HTML is the foundation of a bug-free web
ModernSearch engines prioritize sites with good semantic structure
StandardPart of the HTML5 specification
IdentityThe difference between a "Junior" and a "Senior" developer