Skip to content

    Frontend System Design

    Semantic HTML and Document Structure

    Use native HTML elements to give a page meaning: landmarks, headings, links and buttons, so browsers, screen readers and crawlers can navigate it.

    By Published 12 min read

    • frontend-system-design
    • semantic-html
    • accessibility
    • landmarks
    • headings
    Share

    Standard lessonbeginnerFrontend System Design

    Before this: HTML, CSS and JavaScript Architecture: Structuring a Large Interface

    What you'll learn: By the end of this lesson you will be able to explain what semantic HTML adds beyond appearance, describe how the browser turns markup into an accessibility tree, lay out a page with landmark elements (header, nav, main, section, article), build a sound heading hierarchy, choose between a link and a button, add a skip link, and review a page for structure without special tools.

    Think of a book. A reader can open it, see a table of contents, jump to a chapter, and find the page numbers. Now imagine the same text printed as one long block with large bold text where the chapter titles should be. A sighted reader could still guess; a person using a screen reader, a search engine and a tool that reformats the text would have no chapters to find. Semantic HTML is the table of contents, chapters and page numbers of a web page: markup that says what each part is, not just how it looks.

    The running example is the product page of a grocery marketplace (the front end of the ShopStream marketplace used in this course): a site header with navigation, the product title and details, an "Add to basket" control, a reviews section, related products and a footer. The first version is built almost entirely from div elements; the lesson turns it into a page a person can navigate by structure.

    The core idea

    1. Elements carry meaning. A button is a button, a nav is a navigation block, an h2 is a second-level heading. The browser, assistive technology and crawlers all read that meaning; CSS cannot add it.
    2. Meaning comes with behaviour. Native elements bring roles, names, states and keyboard handling for free. A div brings none of them.
    3. Prefer the native element. The W3C's "Using ARIA" note puts it as the first rule: if you can use a native HTML element or attribute with the semantics and behaviour you require already built in, use it, instead of re-purposing an element and adding an ARIA role, state or property. Its second rule is not to change native semantics unless you really have to.

    This lesson builds on HTML, CSS and JavaScript Architecture, where HTML is the baseline layer, and zooms into that layer: what a well-structured document contains and why.

    From markup to the accessibility tree

    MDN explains that browsers convert markup into the DOM tree, then create an accessibility tree from it, which platform accessibility APIs expose to assistive technology such as screen readers. Each object in that tree has four properties: a name (how to refer to it, such as the text of a link), a description, a role (what kind of thing it is: a button, a navigation bar, a list) and a state (for example checked or unchecked, expanded or collapsed).

    Semantic elements fill in those properties for you: a link's name is its text, and summary carries an expanded or collapsed state. A div with a click handler gives the tree none of that, and every missing property is something you would have to add by hand.

    Figure 1. From markup to what assistive technology sees

    Markup becomes the document tree and then an accessibility tree that assistive technology readsHTML markup to DOM tree (parsed); DOM tree to Accessibility tree (built from); Accessibility tree to Screen reader (exposed)HTML markup: elements, textHTML markupelements, textDOM tree: objectsDOM treeobjectsAccessibility tree: name, role, stateAccessibilitytreename, role, stateScreen reader: via platform APIScreen readervia platform APIparsedbuilt fromexposed

    How to read this: the screen reader never sees your CSS or your layout, it sees the accessibility tree. Choosing the right element decides what that tree contains.

    WCAG success criterion 1.3.1 (Info and Relationships) is the formal version: information, structure and relationships conveyed through presentation can be programmatically determined. A heading that is only a larger bold font conveys structure to the eye alone.

    The document skeleton

    Before any visible content, three things at the top of the document decide how the page is understood.

    • <!doctype html>. MDN says its sole purpose is to stop the browser from switching into "quirks mode", a rendering mode that is incompatible with some specifications.
    • The lang attribute on html. WCAG 3.1.1 says the default human language of each page can be programmatically determined, which matters to people using screen readers and other technologies that convert text to synthetic speech.
    • A title. MDN says the title is shown in the title bar or tab, that a common technique among assistive technology users is to read the page title and infer the page's content, and that titles should be unique per page, with the page's primary purpose first and the site name after. MDN also notes that dynamically updating a title is not automatically announced by screen readers at the time of writing.
    <!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>Fresh Basil, 100 g | ShopStream</title>
    </head>

    Landmarks: the regions of a page

    Landmarks are the large regions of a page that assistive technology can list and jump between. The HTML elements below map to landmark roles.

    Element Role (per MDN) Use it for Watch out for
    header banner when its context is body; otherwise generic Site header, or the introduction to an article or section Nested in article, main, section, nav or aside, it is not a landmark
    nav navigation A major block of navigation links Not every list of links needs one; several nav elements need distinguishing names
    main main The dominant content of the page At most one visible main per document
    section region only if it has an accessible name, else generic A standalone section that has a heading A styling wrapper should be a div
    article Self-contained content A product card, a review, a blog post Give it a heading

    Details worth remembering from MDN. A document must not have more than one main element without the hidden attribute, and the element is preferred over role="main" unless there are legacy browser concerns. nav is intended only for a major block of navigation links, and when a document has several, aria-labelledby can be used to label them. A section should always have a heading with very few exceptions, and a standalone unit that makes sense syndicated, such as a blog post, is better as an article, which MDN describes as a self-contained composition intended to be independently distributable or reusable.

    Figure 2. The landmark layout of the product page

    The product page as landmarks: banner with navigation, main with sections, and a footerheader to nav (contains); h1 and details to section: Reviews (then); section: Reviews to section: Related (then)MAIN (ONE PER PAGE)header: banner landmarkheaderbanner landmarknav: site linksnavsite linksh1 and details: product titleh1 and detailsproduct titlesection: Reviews: named regionsection:Reviewsnamed regionsection: Related: article cardssection:Relatedarticle cardsfooter: legal, contactfooterlegal, contactcontainsthenthen

    How to read this: the zone marks the main element. Everything inside is the page's dominant content; the header and its navigation sit before it and the footer after it. A screen reader user can jump straight to main and skip the repeated header.

    Illustration 1: the minimal example

    The same fragment two ways. Both are structural illustrations and neither was run:

    <div class="top">
      <div class="logo">ShopStream</div>
      <div class="links"><div onclick="go('/fruit')">Fruit</div><div onclick="go('/dairy')">Dairy</div></div>
    </div>
    <div class="content">...</div>
    <header>
      <a href="/">ShopStream</a>
      <nav aria-label="Main">
        <ul>
          <li><a href="/fruit">Fruit</a></li>
          <li><a href="/dairy">Dairy</a></li>
        </ul>
      </nav>
    </header>
    <main id="main-content">...</main>

    The second version tells software there is a banner, a navigation block with two links and a main region. The links are real: MDN says an a with href creates a hyperlink and that pressing Enter on a focused link activates it. The first gives a screen reader generic containers and text.

    Headings: the outline of the page

    Headings are how most people scan a page and a main way screen reader users navigate it. MDN says a common technique is to jump from heading to heading to learn the page's content, so skipping levels leaves the person wondering where the missing heading is. Its rules:

    • A page should generally have a single h1 that describes the page, similar to the title. Multiple h1 elements are allowed by the HTML standard but MDN says this is not best practice.
    • Do not skip heading levels: start at h1, then h2, and so on.
    • Do not use heading elements to resize text; use the CSS font-size property instead.

    So the heading level expresses position in the outline, and the size is a separate styling decision. Pick the level for structure, then style it.

    Figure 3. A heading outline with a skipped level

    flowchart TD accTitle: A heading outline for the product page with one skipped level accDescr: The h1 is the product name. Two h2 headings, Details and Reviews, sit under it. Under Reviews there is an h4 titled Verified buyers that skips the h3 level, which leaves a gap in the outline. A["h1 Fresh Basil, 100 g"] A --> B["h2 Details"] A --> C["h2 Reviews"] C --> D["h4 Verified buyers
    (h3 skipped)"]

    How to read this: the outline is the heading tree. The h4 jumps two levels below its parent, so a person moving by headings finds a gap. The fix is an h3 there, restyled if the h3 looks too large.

    Illustration 2: the realistic example

    The product page body, using the elements above. This is an outline of the structure rather than complete markup, and none of it was run:

    <body>
      <a href="#main-content">Skip to main content</a>
      <header>...banner, search, basket link...</header>
      <main id="main-content">
        <h1>Fresh Basil, 100 g</h1>
        <section aria-labelledby="details-heading">
          <h2 id="details-heading">Details</h2>
          ...
          <form action="/basket/items" method="post">
            <button type="submit">Add to basket</button>
          </form>
        </section>
        <section aria-labelledby="reviews-heading">
          <h2 id="reviews-heading">Reviews</h2>
          <article><h3>Great flavour</h3>...</article>
        </section>
      </main>
      <footer>...</footer>
    </body>

    Three details carry weight. The skip link targets the id on main, the pattern MDN shows; WCAG 2.4.1 requires a mechanism to bypass blocks repeated across pages and lists a link to the main content, landmarks and headings as techniques. The section elements are named by their headings through aria-labelledby, so they become region landmarks. And the button is a real button, whose default type inside a form is submit.

    Both look clickable; they are different tools.

    Link (a with href) Button (button)
    Means Go somewhere: a URL Do something: an action
    Example "Fruit", "Reviews", "Next page" "Add to basket", "Show more", "Submit"
    Keyboard Enter activates it (MDN) Activated by keyboard, mouse, touch, voice or other assistive technology (MDN)
    Inside a form Not a submit control Default type is submit; set type="button" otherwise (MDN)

    MDN's guidance on the link page is direct: anchors are often abused as fake buttons with href="#" or javascript:void(0) plus a click listener; use a button instead, and use a hyperlink only for navigation to a real URL. The rule of thumb: if it goes to an address, make it a link; if it changes something on the current page or sends data, make it a button.

    Figure 4. Choosing the element

    flowchart TD accTitle: Choosing between a link, a button and a landmark element accDescr: A decision tree. If the thing goes to a URL, use a link. If it performs an action on the page or sends data, use a button. If it is a large region of the page, use a landmark element such as header, nav, main or footer. Otherwise use a heading, list or other specific element, and a div only when nothing fits. A{"What is it?"} A -->|"goes to a URL"| L["a with href"] A -->|"does an action"| B["button"] A -->|"a big region"| R["header, nav, main,
    section, article, footer"] A -->|"text structure"| T["h1 to h6, p, ul, ol, table"] A -->|"nothing fits"| D["div or span
    (only then)"]

    How to read this: start with what the thing is for. A generic div or span is the last branch, used for grouping and styling when no element has the meaning you need.

    Illustration 3: a failure, the div soup page

    The original product page has a div header with onclick navigation, headings made from styled div elements and a span that acts as the basket button. For a sighted mouse user it is flawless. For a person using a screen reader there are no landmarks to list, no headings to jump between, and no control to announce; keyboard-only use depends on whatever focus and key handling the team hand-built. WCAG 1.3.1 is the criterion at stake: the structure exists only in the presentation.

    Trade-offs

    Choice Gain Cost
    Native elements first Roles, names, states and keyboard handling included Less freedom over default look and behaviour
    Landmarks everywhere Easy region navigation Too many becomes noise; name the repeated ones
    One h1 and no skipped levels Clear outline Styling must be separated from level
    Skip link Quick way past repeated blocks A focus design to maintain
    ARIA on custom widgets Describes patterns HTML lacks You own behaviour and keyboard support

    Build it

    This lesson has no lab. Its claims come from the cited specifications and MDN pages, the snippets are structural illustrations with no captured output, and nothing here was tested with a screen reader. To explore structure yourself, inspect a page's accessibility tree in your browser's developer tools, or move through it with only the Tab key.

    In practice: restructuring the marketplace product page

    NOTE

    This is a realistic scenario, not a case history. It is a composite built from common production patterns. It describes no specific company or product, and every number in it is an illustrative assumption.

    The situation

    An audit of the product page, run with an accessibility checker and a keyboard-only pass, finds: no main, headings made of styled div elements, a span for the basket control, a lang attribute that is missing, and the same title on every product page. Support has had complaints from a customer who uses a screen reader and cannot find the basket button.

    Starting architecture

    Figure 5. The page as it is today

    Starting architecture: a page of generic containersPage of divs to Accessibility tree (built from); Accessibility tree to Screen reader user (nothing to navigate)Page of divs: classes onlyPage of divsclasses onlyAccessibility tree: mostly genericAccessibilitytreemostly genericScreen reader user: no landmarksScreen readeruserno landmarksbuilt fromnothing to navigate

    How to read this: the warning boxes are where meaning is missing. The user at the end gets an unstructured page, however good the visual design is.

    Options considered

    Option What it fixes What it costs Risk
    Add ARIA roles to the existing div elements Roles appear in the tree Behaviour and keyboard support still hand-built Wrong or redundant roles; contradicts ARIA's first rule
    Replace with native elements Roles, names, states and keys come for free Markup and CSS changes Selectors and scripts that relied on the old structure

    The decision

    Field Decision record
    Context The page is built from generic containers; structure exists only visually.
    Decision Replace with native elements: header, nav, one main, headings in order, named section regions, a real button in a form. Add lang, a unique title and a skip link.
    Consequences, good Landmarks and headings are navigable; the basket control is a control; checks for these are automatable.
    Consequences, bad CSS and scripts tied to the old classes must be updated; heading levels may need restyling.
    Revisit when New templates add custom widgets that need ARIA patterns beyond native elements.

    Rollout and verification

    1. Fix the template, not each page, so all products inherit the structure.
    2. Check the outline: list the headings and landmarks of a product page and read them: one h1, no gaps, one main.
    3. Tab through the page and confirm every control is reachable, shows focus and works.
    4. Have a screen reader user review it. Automated checks cover only part of the problem.

    The 2 a.m. failure

    A promotion banner is injected into the page above the header by a marketing script, with its own h1 and a main element for the promotion text. The page now has two h1 headings and two main elements, and a screen reader's "jump to main" lands on the banner.

    First three checks: (1) list the headings and landmarks on the live page; (2) find which script or template added the extra h1 and main; (3) check whether the injection point is inside the real main. Mitigation: disable the injected block or change its heading and wrapper to non-landmark elements. Follow-up: a test that fails if a page has more than one visible main or more than one h1.

    Architect's notes

    • Structure is a contract with software; review it as you review an API.
    • Name repeated landmarks. Two nav blocks need two distinguishing names.
    • Make structural checks part of the template tests: one main, one h1, lang present, unique title.

    Common mistakes

    • Using div or span for buttons and links.
    • A link with href="#" that acts like a button.
    • Skipping heading levels or choosing a heading for its size.
    • More than one visible main.
    • A section used only for styling, or with no heading.
    • A button in a form without type="button" that unexpectedly submits.

    Key takeaways

    • Browsers build an accessibility tree from the DOM; native elements fill in name, role and state for you.
    • Use native elements first; ARIA is for what HTML cannot express, and its first rule says so.
    • Landmarks (header, nav, main, named section) let people jump between regions; keep one visible main.
    • Headings form the outline: one h1, no skipped levels, never chosen for size.
    • Links go to URLs; buttons do actions; doctype, lang and a unique title are part of the structure.

    Practice exercises

    Exercise 1: Starter (30 min). Write the markup for a page with a header, a navigation of three links, a main area with one h1 and two h2 headings, and a footer. List the landmarks and headings it exposes.

    Exercise 2: Intermediate (2 hours). Take a page of your own and tab through it. List every control you cannot reach or cannot identify by name, and fix each by using the correct native element.

    Exercise 3: Advanced (half day). Write a function that reports, for an HTML string, the number of main and h1 elements, skipped heading levels and sections with no heading. Say which rules in this lesson it cannot check.

    In this course:

    Official documentation

    Ask about this article

    Get answers grounded in this post. AI-generated — based on this article, and may be imperfect.

    Scaled AI Weekly

    Enjoyed this? Get more like it every Monday.

    Real architecture decisions, LLMOps patterns that survive production, and engineering leadership advice — from 12+ years of building at enterprise scale. Free. No spam. Unsubscribe anytime.

    Get new articles by email

    Free. We email a confirmation link first, and you can unsubscribe from any email.

    Join engineers building production AI systems

    Comments