Beyond just putting content on a page, good HTML structure is about organizing that content in a way that makes sense to browsers, search engines, and people using assistive technology. This tutorial introduces you to semantic HTML elements that give meaning to page structure.
What you’ll learn:
Semantic HTML elements and why they matter
Using <header>, <nav>, <main>, and <footer>
The <section> and <article> elements
The <aside> element for sidebars
Creating accessible, well-organized pages
Why structure matters for SEO
Prerequisites:
Semantic HTML means using elements that describe their meaning , not just their appearance. Compare:
<!-- Not semantic - no meaning -->
< div > Welcome to my site </ div >
< div > Home | About | Contact </ div >
< div > My latest article... </ div >
<!-- Semantic - clear meaning -->
< header > Welcome to my site </ header >
< nav > Home | About | Contact </ nav >
< article > My latest article... </ article >
Both render similarly, but semantic HTML:
Helps search engines understand your content
Makes assistive technology work better
Makes your code easier to maintain
Shows your intent to other developers
Here’s a typical semantic page structure:
Interactive code playground requires JavaScript. Here's the code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Blog</title>
</head>
<body>
<header>
<h1>My Blog</h1>
<p>Stories and thoughts about web development</p>
</header>
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
<li><a href="/blog">Blog</a></li>
<li><a href="/contact">Contact</a></li>
</ul>
</nav>
<main>
<article>
<h2>My First Blog Post</h2>
<p>Posted on December 10, 2024</p>
<p>This is the content of my first blog post...</p>
</article>
</main>
<footer>
<p>© 2024 My Blog. All rights reserved.</p>
</footer>
</body>
</html>
The <header> contains introductory content, branding, and navigation:
Interactive code playground requires JavaScript. Here's the code:
<header>
<h1>My Online Portfolio</h1>
<p>Web developer and designer</p>
<img src="https://images.unsplash.com/photo-1453728691169-d74f74d3c161"
alt="My profile"
width="100"
height="100">
</header>
The <nav> element contains navigation links:
Interactive code playground requires JavaScript. Here's the code:
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/services">Services</a></li>
<li><a href="/portfolio">Portfolio</a></li>
<li><a href="/blog">Blog</a></li>
<li><a href="/contact">Contact</a></li>
</ul>
</nav>
Use <nav> for:
Main site navigation
Breadcrumbs (navigation trails)
Table of contents
Pagination links
Don’t use <nav> for:
Every link on the page
Footer links (use <footer> instead)
Single links
The <main> element contains the primary content of your page:
Interactive code playground requires JavaScript. Here's the code:
<main>
<article>
<h2>The Benefits of Learning HTML</h2>
<p>HTML is the foundation of web development...</p>
</article>
<article>
<h2>Getting Started with CSS</h2>
<p>CSS controls the appearance of web pages...</p>
</article>
</main>
<section> groups related content together:
Interactive code playground requires JavaScript. Here's the code:
<main>
<section>
<h2>Introduction</h2>
<p>Welcome to this tutorial...</p>
</section>
<section>
<h2>Getting Started</h2>
<p>First, you'll need...</p>
</section>
<section>
<h2>Advanced Techniques</h2>
<p>Once you're comfortable...</p>
</section>
</main>
Use <section> to:
Group related content
Create logical divisions in your content
Organize topics
Don’t use <section> for:
Styling purposes (use <div> instead)
Sidebar content (use <aside>)
Individual articles (use <article>)
<article> contains content that stands alone:
Interactive code playground requires JavaScript. Here's the code:
<main>
<article>
<h2>First Blog Post</h2>
<p>Posted on December 10, 2024</p>
<p>The content of my blog post...</p>
</article>
<article>
<h2>Second Blog Post</h2>
<p>Posted on December 9, 2024</p>
<p>The content of another blog post...</p>
</article>
</main>
Use <article> for:
Blog posts
News articles
Forum posts
Podcast episodes
Product reviews
User comments
Key difference from <section>:
<article> makes sense on its own
<section> is part of a larger whole
<aside> contains tangentially related content:
Interactive code playground requires JavaScript. Here's the code:
<main>
<article>
<h2>Why Learn HTML</h2>
<p>HTML is essential for all web developers...</p>
</article>
<aside>
<h3>Related Topics</h3>
<ul>
<li><a href="/css">CSS Basics</a></li>
<li><a href="/js">JavaScript Guide</a></li>
<li><a href="/web-design">Web Design</a></li>
</ul>
</aside>
</main>
Use <aside> for:
Sidebars with related links
Supplementary information
Pull quotes
Related articles
Advertising sections
The <footer> contains closing information:
Interactive code playground requires JavaScript. Here's the code:
<footer>
<section>
<h3>Quick Links</h3>
<ul>
<li><a href="/about">About Us</a></li>
<li><a href="/privacy">Privacy Policy</a></li>
<li><a href="/terms">Terms of Service</a></li>
</ul>
</section>
<section>
<h3>Contact</h3>
<p>Email: <a href="mailto:info@example.com">info@example.com</a></p>
<p>Phone: <a href="tel:+1-555-123-4567">+1 (555) 123-4567</a></p>
</section>
<p>© 2024 My Company. All rights reserved.</p>
</footer>
Here’s a complete example combining all structural elements:
Interactive code playground requires JavaScript. Here's the code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Tech Blog</title>
</head>
<body>
<header>
<h1>Tech Blog</h1>
<p>Exploring web development</p>
</header>
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/tutorials">Tutorials</a></li>
<li><a href="/about">About</a></li>
</ul>
</nav>
<main>
<article>
<h2>Understanding HTML Structure</h2>
<p><em>Posted on December 10, 2024</em></p>
<p>Good HTML structure is the foundation of web development...</p>
<p>Semantic elements help browsers understand your content...</p>
</article>
<aside>
<h3>Featured Posts</h3>
<ul>
<li><a href="/post1">Getting Started</a></li>
<li><a href="/post2">Best Practices</a></li>
</ul>
</aside>
</main>
<footer>
<p>© 2024 Tech Blog</p>
<p><a href="/contact">Contact Us</a></p>
</footer>
</body>
</html>
Before you start coding, sketch out your content structure:
What’s the main title/branding? → <header>
How do users navigate? → <nav>
What’s the main content? → <main> with <article> or <section>
Is there supporting information? → <aside>
What goes at the bottom? → <footer>
Semantic structure helps:
Screen Readers:
Users can navigate by heading levels
They can jump to <main> content
They understand <nav> sections
Search Engines:
Better understand your content
Find your main topic (h1 in header)
Index your pages more accurately
Mobile Browsers:
Can reflow content appropriately
Provide better reading modes
Developers:
Your code is self-documenting
Easier to maintain and update
Create a structured page about a topic you know:
Interactive code playground requires JavaScript. Here's the code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Topic</title>
</head>
<body>
<header>
<h1>Your Topic Here</h1>
<p>Brief description</p>
</header>
<nav>
<ul>
<li><a href="#intro">Introduction</a></li>
<li><a href="#details">Details</a></li>
</ul>
</nav>
<main>
<section id="intro">
<h2>Introduction</h2>
<p>Write about your topic</p>
</section>
<section id="details">
<h2>Key Details</h2>
<p>Share important information</p>
</section>
</main>
<footer>
<p>Thank you for reading!</p>
</footer>
</body>
</html>
Experiment with:
Adding more sections
Creating an article instead of sections
Adding an aside with related links
Making footer content more detailed
Using <div> for Everything
Don’t do this:
Use semantic elements instead:
Semantic HTML gives meaning to your page structure
<header> — Top branding and introductory content
<nav> — Navigation links
<main> — Primary content (one per page)
<section> — Groups of related content
<article> — Independent, self-contained content
<aside> — Supplementary content and sidebars
<footer> — Bottom closing content
Semantic structure improves SEO, accessibility, and maintainability
Semantic HTML
Dive deeper into semantic HTML and advanced structures.
Continue →
Forms
Build interactive forms with input validation.
Continue →