Semantic HTML
Learn how to write meaningful HTML that describes the content's purpose and structure, not just its appearance.
What is semantic HTML?
Semantic HTML means using elements that describe their meaning, such as <header>, <nav>, <main>, <article>, <section>, <aside>, <footer>, <button> and <figure>, instead of generic <div>s and <span>s. It makes pages accessible to screen readers, easier for search engines to understand, and easier for developers to read.
<!-- Non-semantic -->
<div class="header"><div class="nav">…</div></div>
<!-- Semantic -->
<header><nav>…</nav></header>
<main>
<article>
<h1>Title</h1>
<p>…</p>
</article>
</main>Interactive Example
Code Editor
<header><strong>My Blog</strong> <nav><a href="#">Home</a> <a href="#">Posts</a></nav></header>
<main>
<article>
<h2>Why semantic HTML matters</h2>
<p>Screen readers and search engines understand this structure.</p>
<figure>
<img src="https://picsum.photos/id/180/240/120" alt="Laptop with code on screen">
<figcaption>Semantic markup in action</figcaption>
</figure>
</article>
<aside>Related posts</aside>
</main>
<footer>© 2026 My Blog</footer>Preview
What is Semantic HTML?
Semantic HTML uses HTML elements according to their meaning rather than their appearance. It describes the structure and content of web pages in a way that both browsers and developers can understand.
Key Principle
Semantic HTML focuses on what content means, not how it looks. Styling should be handled with CSS, while HTML describes structure and meaning.
Benefits of Semantic HTML
- Better Accessibility: Screen readers and other assistive technologies can better navigate and understand content
- Improved SEO: Search engines better understand page structure and content hierarchy
- Easier Maintenance: Code is more readable and maintainable for developers
- Future-Proof: Semantic markup adapts better to new devices and technologies
- Consistent Styling: CSS can target semantic elements more effectively
Semantic vs Non-Semantic Elements
<div class="header">
<div class="title">Page Title</div>
<div class="nav">
<span class="nav-item">Home</span>
<span class="nav-item">About</span>
</div>
</div>
<div class="content">
<div class="article">
<div class="article-title">Article</div>
<div class="article-text">Content...</div>
</div>
</div>Uses generic div elements with class names to indicate meaning
<header>
<h1>Page Title</h1>
<nav>
<a href="#home">Home</a>
<a href="#about">About</a>
</nav>
</header>
<main>
<article>
<h2>Article Title</h2>
<p>Content...</p>
</article>
</main>Uses meaningful HTML elements that describe content purpose
HTML5 Semantic Elements Reference
header
Introductory content or navigation aids
<header>Site navigation</header>nav
Section with navigation links
<nav>Menu items</nav>main
Dominant content of document body
<main>Primary content</main>footer
Footer information for document/section
<footer>Copyright info</footer>aside
Content aside from main content
<aside>Sidebar content</aside>article
Self-contained content that could stand alone
<article>Blog post</article>section
Distinct section of content with a heading
<section>Chapter</section>figure
Self-contained content referenced from main flow
<figure>Image with caption</figure>figcaption
Caption or legend for figure element
<figcaption>Photo description</figcaption>time
Machine-readable time or date
<time datetime="2024-01-15">Jan 15</time>mark
Highlighted or marked text
<mark>Important text</mark>address
Contact information
<address>Contact details</address>details
Disclosure widget with summary
<details>Expandable content</details>Semantic HTML Best Practices
- Use headings (h1-h6) to create proper document outline
- Choose elements based on meaning, not appearance
- Use only one main element per document
- Include alternative text for images
- Use landmarks (header, nav, main, footer) consistently
- Provide descriptive link text
- ✗Using div for everything instead of semantic elements
- ✗Skipping heading levels (h1 to h3, skipping h2)
- ✗Using multiple main elements in one document
- ✗Choosing elements based on default styling
- ✗Missing alt attributes on informative images
- ✗Using "click here" or "read more" as link text
SEO and Accessibility Impact
Search engines use semantic HTML to better understand and rank your content:
- Heading hierarchy: H1-H6 elements help search engines understand content structure
- Article elements: Help identify main content vs navigation/ads
- Time elements: Provide publication dates for content freshness
- Navigation structure: Helps crawlers understand site architecture
Semantic HTML provides essential context for assistive technologies:
- Screen readers: Can navigate by headings, landmarks, and regions
- Keyboard navigation: Semantic elements provide natural tab order
- Content understanding: Elements like time, address provide context
- Document outline: Proper heading structure creates logical navigation
Quick Reference
Essential Elements:
<header> - Page/section header
<nav> - Navigation links
<main> - Primary content
<article> - Standalone content
<section> - Themed content group
<aside> - Sidebar content
<footer> - Page/section footerContent Elements:
<time> - Dates and times
<address> - Contact information
<figure> - Media with caption
<details> - Disclosure widget
<summary> - Details summary
<mark> - Highlighted text
<abbr> - AbbreviationsSemantic HTML — step by step
Replace div soup with semantic elements
Instead of div for every container, use header, nav, main, article, section, aside, and footer. Each element communicates purpose to browsers and assistive technology.
🎯 Quick Check
Which HTML element is best for wrapping the main, unique content of a page?
Semantic HTML: summary
Key points
- Landmark elements (
header,nav,main,aside,footer) let screen-reader users jump between regions. - Native interactive elements (
<button>,<a>,<input>) come with keyboard support and accessibility built in. - Semantic markup helps search engines identify the main content and its structure.
- Choose elements for meaning; CSS handles the appearance of any element.
Common mistakes
<div onclick>instead of<button>, which isn't focusable or keyboard-accessible.- Using
<section>as a generic wrapper with no heading.
Frequently asked questions
›Why is semantic HTML important?
It improves accessibility (screen readers understand the page structure), SEO (search engines identify the main content), and maintainability (the code describes itself).
›Does semantic HTML improve SEO?
Indirectly, yes. Clear headings, <main>, <article> and descriptive links help search engines parse your content, and accessible pages tend to perform better overall.