Menu

Semantic HTML: Tags, Page Structure and Accessibility

Semantic HTML means choosing tags for what the content is, not how it looks. Learn the semantic layout tags (header, nav, main, article, aside, footer), what they give screen readers and search engines, and how to check your page structure.

This page includes runnable editors - edit, run, and see output instantly.

What semantic HTML is

Semantic HTML means picking each tag for what the content is: navigation goes in <nav>, the main content in <main>, a blog post in <article>. The tags look like plain boxes, but they tell the browser, screen readers and search engines what each part of the page does. Here is a full page built from the semantic layout tags, with each one outlined and labelled:

Delete the <style> element and the page looks like plain text, but the structure is still there for anyone reading the code, and for software that reads it without looking at the pixels.

The semantic layout tags

TagUse it forScreen reader landmark
<header>The intro of the page or of an article: logo, title, bylinebanner (only when it is not inside article, aside, main, nav or section)
<nav>A block of major navigation linksnavigation
<main>The content unique to this page, once per pagemain
<article>A self-contained piece that makes sense on its own: a post, a comment, a product cardnone by default
<section>A themed group of content with its own headingregion, only when it has an accessible name
<aside>Related content beside the main flow: a sidebar, a notecomplementary
<footer>Closing info of the page or of an article: copyright, author, linkscontentinfo (only at page level)

Each tag has its own page with more detail: header, nav, section and footer. This page covers how they fit together.

Why not just use div

A page built only from <div> elements can look identical to a semantic one. The difference is what the markup says. Press the buttons to outline the elements that carry meaning in each version:

The div version finds 0, the semantic version finds 4. That is what assistive technology sees: a screen reader user can jump straight to the navigation or the main content on the semantic page, and has to read through everything on the div page. Class names like class="nav" mean nothing to the browser.

<div> is still the right choice for boxes that exist only for styling or layout, like the .cols flex wrapper in the first example.

main, article and aside

<main> wraps what is unique to this page and appears once. Inside it, <article> marks content that would make sense copied to another site on its own, and <aside> marks content that is related but could be removed without breaking the article:

The article has its own <header> and <footer>. They are not limited to the page level: each one introduces or closes its nearest article or section. The <time datetime> element gives the date in a machine-readable form while showing it in a human one.

Check your heading outline

Headings are the other half of the structure. Screen reader users often move through a page heading by heading, so the levels should read like a table of contents with no skipped levels. This script prints the outline of the page it runs in:

The h4 under "Brewing" skips a level. Change it to h3 and the outline reads cleanly. Pick heading levels by structure, and change their size with CSS if you want them bigger or smaller.

More semantic tags

Semantics are not only about layout. These text-level tags carry meaning too:

TagMeaning
<strong>Important text (bold by default)
<em>Stressed emphasis (italic by default)
<figure> and <figcaption>An image, chart or code sample with its caption
<time datetime="...">A date or time in a machine-readable form
<address>Contact details for the page or article author
<mark>Highlighted text, such as a search match
<abbr title="...">An abbreviation with its full form
<button>Something that performs an action

Hover the "W3C" abbreviation to see its full form in a tooltip.

Common mistakes

  • Using a tag for its look. <blockquote> is for quotations, not indentation; <h3> is for a heading level, not for medium-sized bold text. Style with CSS.
  • Wrapping everything in <section>. A section should have a heading and a theme. If you need a box for styling, use <div>.
  • More than one visible <main>. Keep one per page, and never nest it inside <article>, <aside>, <header>, <nav> or <footer>.
  • Putting every link list in <nav>. Save it for major navigation blocks, like the site menu or a table of contents. A few links in a footer do not need one.
  • Clickable <div> elements. A <div onclick> cannot be reached with the keyboard. Use <button> for actions and <a href> for navigation.

Frequently Asked Questions

What is semantic HTML?

Semantic HTML is markup where each tag describes the meaning of its content: <nav> for navigation, <article> for a self-contained piece, <button> for a button. The browser, screen readers and search engines can then understand the page without guessing from class names or styles.

What are the semantic tags in HTML?

The layout tags are <header>, <nav>, <main>, <article>, <section>, <aside> and <footer>. Other common semantic tags include <figure>, <figcaption>, <time>, <address>, <strong>, <em> and the headings <h1> to <h6>.

Is div a semantic element?

No. <div> has no meaning of its own; it is a generic box for styling and layout. Use it when no semantic tag fits, and use <header>, <main>, <nav> and the others when one does.

What is the aside tag used for?

<aside> holds content related to the main content but not part of its flow: a sidebar, a box of related links, a glossary note or a pull quote. At page level, screen readers list it as a complementary landmark.

How many main elements can a page have?

One visible <main> per page. It wraps the content that is unique to that page, and it should not sit inside <header>, <nav>, <article>, <aside> or <footer>.

Does semantic HTML help SEO?

It helps search engines understand which part of the page is the main content, which is navigation and how headings relate. It is not a ranking shortcut on its own, but it removes guesswork and it improves accessibility, which is worth doing anyway.

Coddy programming languages illustration

Learn to code with Coddy

GET STARTED