liveBook · Manning

Semantic markup

As explained in Architecting Accessibility

Semantic HTML is the use of HTML elements whose names and structure convey the meaning, role, and organization of content.

A page can look organized while leaving a screen reader user with little structure to navigate. Styling text like a heading does not make it a heading. Semantic markup uses HTML elements according to their purpose, so meaning does not depend on appearance alone. section 2.4 section 2.5

Start with a question: what is this content or control? Use a heading for a heading, a list for a list, a table for tabular data, and a button for an action. Prefer these native elements to generic div and span containers when a meaningful element exists. The browser can then communicate structure and built-in behavior to assistive technologies. section 2.5.1 section 2.5

Listing 2.1 HTML code with little emphasis on semantics
<!DOCTYPE html>
<html>
  ...
  <body>
    <div class="header">
      <span class="navigation">
        <a href="DivSoup.html">Home</a>
        <a href="#">Minestrone</a>
        <a href="#">Contact</a>
      </span>
      <span class="pageheading">
        Welcome to DivSoup!
      </span>
    </div>
    <div class="content">
      <div>
        <span class="subheading">A brief history</span>
          <div>
            Soup is soup. Lorem ipsum...<br>
            Nothing much to add. Nullam ut ....
          </div>
      </div>
      <div>
        <span class="subheading">Main ingredients</span>
        <br>
        <div>
          Our default soup is made with the following:
          <br>
          - div tags
          <br>
          - a sprinkle of spans
        </div>
      </div>
    </div>
    <div class="footer">
      © Soups and such!
      <br>
      <span class="links">
        <a href="#">Contact us</a>
        <a href="#">Sitemap</a>
      </span>
    </div>
  </body>
...
</html>

Compare the page built largely from div and span containers: its visual labels do not supply heading, list, or page-region semantics. section 2.5.1

  <main> #A
    <section> #B
      <h2>A brief history</h2> #C
      <p>Soup is soup. Lorem ipsum...</p> #D
      <p>Nothing much to add. Nullam ut ....</p>
    </section>
    ...
  </main>

See how main, section, h2, and p turn part of that page into a main region with a headed section and paragraphs. section 2.5.1

Apply the same approach across the page: header, main, nav, and footer identify key regions; heading levels organize content; and real list items replace lines separated by breaks. These choices help people find their way through a page rather than reconstructing its organization from its visual design. section 2.5.1 section 5.2

The browser derives an accessibility tree from the document. It carries useful structure and information such as roles, names, states, and relationships to assistive technologies, while leaving out purely decorative details. Semantic markup gives that tree more reliable information to convey. section 2.5.3

TIP: Reach for ARIA when native HTML cannot express what a custom component needs—not as a substitute for an available element. ARIA can describe a component, but it does not supply its expected keyboard behavior. Choosing the native element first usually means less behavior to build, test, and maintain. section 2.5.2 section 2.5.1

How Architecting Accessibility covers it

How deep it goes
Works through a generic-container page refactoring and explains the accessibility tree; treats custom component behavior separately.
Examples
Contrasts a div-and-span page with headed sections and lists, and compares a native button with a custom substitute.
What it assumes
Introduces native-element selection without requiring ARIA expertise; reserves ARIA and JavaScript for custom components.
What you can do after
Apply it via native HTML elements to make page regions, headings, lists, and controls easier to interpret and navigate.
How it connects
Connects HTML elements to landmarks, headings, the accessibility tree, keyboard interaction, and ARIA.

Also explained in

Compare how 7 books explain semantic markup →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Architecting Accessibility. The section links point to the parts of the book it draws on.