Semantic HTML and Keyboard Accessibility
HTML Living Standard
Semantic elements state what part of the page they represent. Assistive tools can expose important regions as landmarks users can jump between.
On this page
The main content <main>
Place the page’s primary content inside main. Repeated site navigation usually sits outside it. Use one visible main landmark per page so visitors can quickly find the content unique to that page.
How to try it In index.html, replace the content between <body> and </body> with this example. Save the file and reload it in the browser.
<main id="main-content">
<h1>Product catalog</h1>
<p>See our available products and prices.</p>
</main>
What to expect The accessibility tree exposes a main landmark containing the heading and paragraph.
Group related content with <section>
A section gives a distinct topic a place within the page. Give it a heading that describes the topic. For a region assistive tools can name, use aria-labelledby to point at the heading’s ID.
How to try it In index.html, replace the content between <body> and </body> with this example. Save the file and reload it in the browser.
<main>
<h1>Product catalog</h1>
<section aria-labelledby="stationery-heading">
<h2 id="stationery-heading">Stationery</h2>
<p>Blue and black pens are available.</p>
</section>
</main>
What to expect Stationery appears as a section title below Product catalog. The named region is available in the accessibility tree.
Mark independently readable content with <article>
An article is a complete piece of content, such as a news update, blog post, or review. A section can contain several articles when each can be read on its own.
How to try it In index.html, replace the content between <body> and </body> with this example. Save the file and reload it in the browser.
<section>
<h2>Store news</h2>
<article>
<h3>New products</h3>
<p>Three new products arrive Friday.</p>
</article>
</section>
What to expect You can move the New products article to another page and its heading and message still make sense together.
Keyboard focus and skip links
Focus is the element that currently receives keyboard input. Tab moves through links and form controls in the document’s usual order. Keep a visible focus indicator. A skip link before the site menu lets keyboard users move directly to the main content. tabindex="-1" allows main to receive focus as the target without placing main itself in the normal Tab sequence.
How to try it In index.html, replace the content between <body> and </body> with this example. Save the file and reload it in the browser.
<a href="#main-content">Skip to main content</a>
<header><nav aria-label="Main"><a href="/">Home</a></nav></header>
<main id="main-content" tabindex="-1">
<h1>Events</h1>
<a href="/events">View upcoming events</a>
</main>
What to expect Press Tab to focus the skip link and Enter to reach main. Press Tab again to move to the events link.