Frontend School
DashboardProblemsLearnPracticeMock InterviewReportsStatsBuy Credits
DashboardProblemsLearnPracticeMock Interview
HTML & Accessibility (a11y)
  1. 1.HTML Fundamentals: Structure & Core Elements
  2. 2.Lists, Tables & Basic Forms
  3. 3.Semantic HTML5 & Document Outline
  4. 4.Advanced Forms & Input Validation
  5. 5.Multimedia & Embedded Content Accessibility
  6. 6.Introduction to ARIA: Roles & Landmarks
  7. 7.ARIA States & Properties for Dynamic Content
  8. 8.Keyboard Accessibility & Focus Management
  9. 9.Advanced Accessibility Patterns & Custom Controls
  10. 10.Accessibility Testing, WCAG & Interview Prep
HTML & Accessibility (a11y)
03

Web Fundamentals · Lesson 3 of 10 · 5 min

Semantic HTML5 & Document Outline

This is how you show you build for humans and machines, not just for browsers.

After this, you'll be able to explain why a page full of <div>s is a red flag and how to structure a document so a screen reader can navigate it as easily as a search engine can index it. This isn't just about "good practice"; it's a test of whether you think beyond the visual output.

Stop writing div soup

Your primary job is to give meaning to raw information. Using a <div> for everything is like putting all your food in identical, unlabeled containers. It works, but it's inefficient and confusing.

Semantic HTML means using tags that describe the purpose of the content. This gives immediate context to screen readers, search engines, and the next developer who has to maintain your code.

  • Accessibility: A screen reader user doesn't scan a page visually; they navigate by landmarks (<nav>, <main>) and headings (<h2>, <h3>). Non-semantic HTML is like a building with no signs or room numbers.
  • SEO: Search engines use this structure to understand the hierarchy and importance of your content, which influences ranking.
  • Maintainability: main > article > section > h3 tells a story. div > div > div > div tells you nothing.

The trap: An interviewer gives you a simple layout and asks you to write the HTML. If you start with <div class="header"> instead of <header>, you've already shown a gap in your fundamentals.

Map the page with landmark roles

A few key elements define the high-level structure of nearly every page. These are called landmark roles, and assistive technologies depend on them.

<header>: The introduction or navigational support for a page or a section. You can have a main site <header> and a separate <header> inside an <article>.

<nav>: Contains the primary navigation links. Don't use it for every group of links on a page; it's for major site or page navigation, not for a list of social media icons in the footer.

<main>: The main, unique content of the page. There must be only one <main> element, and it cannot be a child of <article>, <aside>, <footer>, <header>, or <nav>.

<aside>: For content that's tangentially related to the main content. Think "Related Articles" sidebars or call-out boxes. If the content was removed, the main content should still make perfect sense.

<footer>: The footer for a page or section. It usually contains metadata like author info, copyright, or related links. Like <header>, you can have more than one.

Group content with section vs. article

This is a common point of confusion and a frequent interview question.

<article> is for self-contained, distributable content. If you could syndicate it in an RSS feed and it would make sense on its own, it's an <article>. Examples: a blog post, a news story, a user comment.

<section> is for grouping thematically related content. It almost always needs a heading. Think of it as a chapter in a book. A <section> inside an <article> is a chapter of that article. A <section> on the homepage might group "Latest News".

A good rule of thumb: Could this content be read on its own, out of context? If yes, use <article>. If it only makes sense as part of the surrounding page, use <section>.

Here is a typical refactor from non-semantic divs to a meaningful structure.

Before: Ambiguous divs

<div id="header">
    <h1>Welcome to My Site</h1>
    <div class="nav">
        <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
        </ul>
    </div>
</div>
<div id="content">
    <h2>About Us</h2>
    <p>This is some content about our company...</p>
</div>
<div id="footer">
    <p>&copy; 2023 My Awesome Website</p>
</div>

After: Clear and Semantic

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My Awesome Website</title>
</head>
<body>
    <header>
        <h1>Welcome to My Site</h1>
        <nav>
            <ul>
                <li><a href="#">Home</a></li>
                <li><a href="#">About</a></li>
            </ul>
        </nav>
    </header>

    <main>
        <section>
            <h2>About Us</h2>
            <p>This is some content about our company, explaining who we are and what we do.</p>
        </section>
    </main>

    <footer>
        <p>&copy; 2023 My Awesome Website. All rights reserved.</p>
    </footer>
</body>
</html>

Build a logical document outline

Browsers and screen readers create a "document outline" from your heading elements (<h1>-<h6>) to form a table of contents. A broken outline is a major accessibility failure.

  1. Use exactly one <h1> per page. This is the main title of the page. While the HTML5 spec technically allows multiple <h1>s if they are in different sectioning elements, it has poor screen reader support and is bad practice. Don't do it.
  2. Never skip heading levels. Don't jump from an <h2> to an <h4>. It breaks the logical hierarchy and confuses users of assistive tech who navigate by headings.
  3. Don't use headings for styling. If you just want big, bold text, use CSS. Headings are for structure, not aesthetics.

Interview Question: "How does a screen reader user navigate a long article, and how does your HTML support that?"

Answer: "They often use a shortcut to bring up a list of all headings on the page, which acts as a table of contents. They can then jump directly to the section they're interested in. This only works if the HTML uses a logical and unbroken heading hierarchy, like h2 for main sections and h3 for sub-sections, to create a clear document outline."

A well-structured page has a clean outline.

Add meaning to inline content

Semantics aren't just for page layout.

  • <figure> and <figcaption>: Wrap images, diagrams, or code snippets that are referenced in the text. The <figcaption> provides a caption that is programmatically linked to the figure.
  • <time>: Use this to wrap dates and times. The datetime attribute provides a machine-readable version: <time datetime="2023-10-26">October 26, 2023</time>.
  • <strong> vs. <b>, <em> vs. <i>: This is a classic distinction. <strong> indicates strong importance, while <em> indicates stress or emphasis. <b> (bold) and <i> (italic) are purely presentational and convey no semantic meaning. Always prefer <strong> and <em> when you mean to add importance or emphasis.

Try it

Find a news site or blog you read. Open the developer tools on an article page and inspect the element structure. Mentally refactor the page, replacing divs with appropriate semantic tags and checking if the heading structure is logical. See if you can spot any skipped heading levels or misuse of <article> and <section>.

Next: We'll apply these structural principles to interactive elements in Advanced Forms & Input Validation.

Lock it in — apply this lesson under interview conditions.

Try an AI mock interview
Previous

Lists, Tables & Basic Forms

Next

Advanced Forms & Input Validation