After completing this lesson, you will understand what semantic HTML means and why it matters for accessibility and website structure. You will be able to identify semantic HTML tags and know when to use them appropriately. You will also recognize the difference between semantic and non-semantic markup, and understand how semantic HTML improves the experience for users who rely on assistive technologies.
You should be comfortable with the basic HTML structure covered in Lesson 01, including understanding how tags work, creating headings and paragraphs, and the overall document structure with head and body sections.
Semantic HTML refers to using HTML tags that clearly describe their meaning and purpose. The word "semantic" relates to meaning, so semantic HTML is markup that carries meaning about the content it contains, not just instructions about how it should look. When you use a semantic tag like <article> or <nav>, you're telling browsers, search engines, and assistive technologies what that section of your page represents, not just how it should be styled.
This matters because websites are read and interpreted by many different systems, not just visual browsers. Screen readers used by people with visual impairments rely on semantic HTML to understand page structure and navigate content effectively. Search engines use semantic HTML to better understand the content and context of your pages, which can improve how your site appears in search results. Browser features like reader mode that strip away distractions depend on semantic markup to identify the main content. Even developers working on your code in the future will find it much easier to understand and maintain if the HTML clearly expresses the meaning of each section.
Before HTML5, developers often used generic <div> tags for everything, adding class names like "header" or "navigation" to indicate purpose. While this worked for visual styling, it didn't provide any meaningful structure that machines or assistive technologies could understand.
Semantic HTML5 tags solve this problem by providing elements specifically designed to represent common page sections and content types. Using these tags creates:
HTML5 introduced many semantic elements designed to represent common patterns found on web pages. Understanding when and how to use these elements helps you create better-structured, more accessible websites.
<header> ElementThe <header> element represents introductory content or navigational aids for its nearest ancestor section or the entire page.
Important: While you might think of "header" as just the top of a page, a header element can actually appear multiple times on a page:
This element typically contains:
<nav> ElementThe <nav> element represents a section of a page whose purpose is to provide navigation links. This could be:
Note: Not every link on your page should be inside a <nav> element - only those that form a major navigation block. Including links within a nav element helps screen readers identify navigation areas and allows users to skip directly to navigation if they wish.
<main> ElementThe <main> element represents the dominant content of the document.
Important rules:
<main> element per page<article>, <aside>, <header>, <footer>, or <nav>The main content is the unique content of this page that isn't repeated across other pages. Screen readers can use this element to jump directly to the main content, which is especially useful on pages with extensive navigation or headers.
<article> ElementThe <article> element represents a self-contained composition that could be distributed independently from the rest of the site.
Examples include:
An article should have its own heading structure and could theoretically be republished elsewhere without losing meaning. If your page has multiple independent pieces of content, each one should be wrapped in its own <article> element.
<section> ElementThe <section> element represents a generic standalone section of a document.
Important: Sections should always have a heading that describes their purpose.
Use <section> to group related content that forms a distinct part of a larger whole. For example, if you have a page with multiple topics, each topic could be its own section. The key is that each section should represent a distinct thematic grouping of content.
<aside> ElementThe <aside> element represents content that is tangentially related to the content around it. This often appears as:
Examples include: related links, author information, or definitions that enhance understanding but aren't essential to the main content flow.
<footer> ElementThe <footer> element represents footer content for its nearest sectioning element or the entire page. Footers typically contain:
Like headers, footers can appear multiple times on a page - once for the entire document and within individual sections.
<article> and <section>Understanding when to use <article> versus <section> can be confusing at first. A helpful way to think about it is:
<article>: If the content makes complete sense on its own and could be distributed independently<section>: If the content is part of a larger whole and needs context from the pageWhen in doubt: Consider whether someone reading just that content would understand it without the rest of the page. If yes, use <article>. If no, use <section>.
To understand the difference semantic HTML makes, consider how the same content structure could be marked up in different ways.
Non-semantic markup relies on generic <div> elements with class names that only provide visual organization. For example:
<div class="navigation">
<a href="/">Home</a>
<a href="/about">About</a>
</div>
Problems with this approach:
<div> from any other <div> on the pageSemantic markup uses elements that carry inherent meaning about the content they contain. Using <nav> instead:
<nav>
<a href="/">Home</a>
<a href="/about">About</a>
</nav>
Benefits of this approach:
This difference becomes even more important when you consider how search engines and other automated systems parse web pages:
<article> element represents the main article content<article> may receive different treatment in search rankings than content in <aside>By using semantic HTML, you create websites that are more accessible, better indexed, and easier to maintain.
Creating a well-structured blog post page demonstrates how semantic HTML elements work together to create meaningful document structure. We'll build a page that includes a header, navigation, main content area with an article, and a footer, showing how each semantic element contributes to the overall page organization.
Start with the basic HTML document structure you learned in Lesson 01. Inside the <body> element, begin with a <header> element that contains the site title and main navigation.
Why use <header>? The header wraps both the site branding and the primary navigation because these elements together form the introductory section of the page.
Inside the header, place a <nav> element containing your navigation links. This clearly identifies the navigation section for assistive technologies and helps users navigate your site efficiently.
After the header, add a <main> element. This will contain the primary content of your page.
Inside main, place an <article> element for your blog post. The article element is appropriate here because a blog post is self-contained content that makes sense independently. Within the article, use:
<h2>, <h3>, etc.) to structure the content<p>) for text<section> elements to group related content within the articleIf you want to include related links or author information, add an <aside> element. Place it:
Finally, add a <footer> element after the main content to contain:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Blog Post</title>
</head>
<body>
<header>
<h1>My Blog</h1>
<nav>
<a href="/">Home</a>
<a href="/about">About</a>
<a href="/contact">Contact</a>
</nav>
</header>
<main>
<article>
<h2>Understanding Semantic HTML</h2>
<p>Semantic HTML helps create accessible websites...</p>
<section>
<h3>What Makes HTML Semantic</h3>
<p>Semantic tags carry meaning about content...</p>
</section>
</article>
<aside>
<h3>Related Posts</h3>
<ul>
<li><a href="#">Previous Post</a></li>
</ul>
</aside>
</main>
<footer>
<p>© 2024 My Blog. All rights reserved.</p>
</footer>
</body>
</html>
Notice how each semantic element clearly communicates its purpose:
This structure makes your page more accessible and easier for both humans and machines to understand. Each semantic element serves a clear purpose and communicates meaning beyond just visual appearance.
Create an HTML page about your favorite hobby or interest. Structure it using semantic HTML5 elements including a header with navigation, a main section containing an article, and a footer. Within the article, organize your content into logical sections using the section element. Each section should have its own heading. Include an aside element with related information or additional resources about your topic.
After creating your page, test it by viewing it in a browser. Consider how the semantic structure helps organize your content logically. Think about how a screen reader user would experience navigating your page, and how each semantic element provides context about what type of content it contains.
Semantic HTML uses tags that carry meaning about their content, not just styling instructions. This creates more accessible websites that work better with assistive technologies, search engines, and other automated systems. HTML5 provides semantic elements like header, nav, main, article, section, aside, and footer that represent common page structures and content types.
Choosing the appropriate semantic element for your content improves the structure and meaning of your HTML documents. While you can still use div elements when no semantic element fits, preferring semantic elements whenever possible creates better, more maintainable, and more accessible web pages. The goal is to write HTML that clearly communicates both to visual browsers and to all the other systems that need to understand your content.
With a solid understanding of HTML structure and semantic markup, you're ready to learn how to style your pages with CSS. Lesson 03 covers CSS basics, teaching you how to add colors, fonts, spacing, and other visual styling to bring your HTML content to life.
Mozilla Developer Network. "HTML Semantic Elements." MDN Web Docs. https://developer.mozilla.org/en-US/docs/Glossary/Semantics
Mozilla Developer Network. "HTML5 Semantic Elements Reference." MDN Web Docs. https://developer.mozilla.org/en-US/docs/Web/HTML/Element
WebAIM. "Semantic Structure: Regions and Landmarks." WebAIM. https://webaim.org/techniques/semanticstructure/
W3C. "HTML5: A vocabulary and associated APIs for HTML and XHTML." W3C Recommendation. https://www.w3.org/TR/html5/