Skip to content
Velloreth
Web Development 6 min read

HTML Semantic Elements: Why They Matter and How to Use Them

Semantic HTML describes meaning, not appearance. Learn the elements, the accessibility and SEO benefits, and the common mistakes to avoid.

By

What semantic HTML is

Semantic HTML uses elements that describe the meaning of their content.

<!-- Not semantic: meaning is lost -->
<div class="header">
  <div class="nav">...</div>
</div>
<div class="main">
  <div class="post">...</div>
</div>

<!-- Semantic: meaning is explicit -->
<header>
  <nav>...</nav>
</header>
<main>
  <article>...</article>
</main>

Both render identically by default. The difference is that the second version tells browsers, screen readers, and search engines what each region is.

Why it matters

Accessibility. Assistive technology relies on semantics. A screen reader can list the page’s landmarks and jump to the main content. It announces a button as a button and a nav as navigation.

Keyboard access. A real button is focusable and responds to Enter and Space. A div with a click handler is not focusable and does nothing on Enter.

SEO. Search engines use structure to understand a page. Heading hierarchy and landmarks are the most relevant signals.

Browser features. Reader mode, translation, and form autofill all depend on semantics. A form built from divs does not autofill.

Maintainability. <nav> is clearer than <div class="nav-wrapper">. The intent is in the element name.

The landmarks

Landmarks are the top-level regions of a page. They let assistive technology navigate by region.

<body>
  <header>
    <nav aria-label="Main">...</nav>
  </header>

  <main>
    <article>...</article>
    <aside>...</aside>
  </main>

  <footer>...</footer>
</body>
ElementMeaning
headerIntroductory content, often a logo and nav
navA block of navigation links
mainThe primary content, once per page
asideTangentially related content, like a sidebar
footerClosing content, often links and copyright
sectionA thematic grouping, usually with a heading
articleSelf-contained content that stands alone

Rules worth knowing:

  • One main per page. It marks the primary content.
  • header and footer can nest. A page header and an article header are both valid.
  • nav is for major navigation. A list of links in a footer does not need nav unless it is a navigation block.
  • section needs a heading. If you cannot give it one, use a div.

article versus section

The distinction confuses people, and the test is simple.

article — would this make sense on its own, syndicated elsewhere? A blog post, a comment, a product card, a forum post.

section — is this a thematic grouping within a larger document, with a heading? “Installation”, “Configuration”, “Troubleshooting”.

<article>
  <h1>Deploying to Cloudflare Pages</h1>

  <section>
    <h2>Prerequisites</h2>
    <p>...</p>
  </section>

  <section>
    <h2>Configuration</h2>
    <p>...</p>
  </section>
</article>

The article is the whole post. The sections are its parts. Both are semantic, and both are useful.

button versus a

This is the most consequential distinction in practice.

<!-- Wrong: an action styled as a link -->
<a href="#" onclick="openDialog()">Open settings</a>

<!-- Right: an action is a button -->
<button type="button" onclick="openDialog()">Open settings</button>
<!-- Wrong: navigation styled as a button -->
<button onclick="location.href='/about'">About</button>

<!-- Right: navigation is a link -->
<a href="/about">About</a>

The rules:

  • button for actions — submit, open, close, toggle, delete.
  • a for navigation — moving to another URL.

Why it matters:

  • A link can be opened in a new tab, copied, and bookmarked. A button cannot.
  • A button responds to Enter and Space. A link responds to Enter only.
  • A screen reader announces “link” or “button”, and the user’s expectation differs.
  • A link with href="#" breaks the back button and the URL.

Forms

Form semantics drive autofill, validation, and accessibility.

<form>
  <label for="email">Email address</label>
  <input id="email" name="email" type="email" required autocomplete="email" />

  <label for="password">Password</label>
  <input id="password" name="password" type="password" required autocomplete="current-password" />

  <button type="submit">Sign in</button>
</form>

Each attribute earns its place:

  • label with for — clicking the label focuses the input, and screen readers announce it.
  • type="email" — mobile keyboards show the @ key, and browsers validate the format.
  • autocomplete — password managers and browsers fill the field correctly.
  • required — the browser blocks submission and announces the error.
  • name — the field is included in the submission.

A form built from divs and click handlers loses all of this.

Headings

Heading hierarchy is a semantic structure, not a styling choice.

<!-- Wrong: skipped levels, chosen for size -->
<h1>Page title</h1>
<h4>Section</h4>
<h6>Subsection</h6>

<!-- Right: sequential, chosen for structure -->
<h1>Page title</h1>
<h2>Section</h2>
<h3>Subsection</h3>

Rules:

  • One h1 per page, describing the page’s main topic.
  • Do not skip levels. An h2 followed by an h4 confuses screen reader navigation.
  • Do not choose a heading for its size. Use CSS for that.

Screen reader users navigate by heading, and a broken hierarchy makes the page hard to traverse.

Common mistakes

Clickable divs. No keyboard access, no focus, no announcement. Use a button.

div soup. Everything is a div, so nothing has meaning. Use the semantic element when one fits.

section without a heading. If it has no heading, it is a div.

Multiple main elements. There should be one.

Skipped heading levels. Breaks screen reader navigation.

Placeholder as label. The placeholder disappears when typing, and screen readers may not announce it. Use a real label.

alt text missing. Every meaningful image needs alt text; decorative images need alt="".

aria-label on everything. ARIA is a patch for missing semantics, not a replacement. Use the right element first.

Practical guidance

  • Choose the element for its meaning, then style it.
  • Use landmarks — header, nav, main, aside, footer.
  • Use button for actions and a for navigation.
  • Give every section a heading, or use a div.
  • Keep one h1 and do not skip heading levels.
  • Label every form field with a real label.
  • Use div only for presentational grouping.
  • Reach for ARIA only when no element fits.

For the related practices, see css-pseudo-classes-guide and css-flexbox-complete-guide. For the broader context, css-grid-complete-guide and css-specificity-explained.

Quotable summary

Semantic HTML uses elements that describe the meaning of their content rather than generic containers, and the meaning is available to browsers, screen readers, and search engines. The main landmarks are header, nav, main, aside, and footer, and they let assistive technology jump between regions. Use button for actions and a for navigation, because a clickable div breaks keyboard access, focus, and screen reader announcements. An article is self-contained content that would make sense on its own, while a section is a thematic grouping that needs a heading. Semantics come first and styling second, and ARIA is a patch for missing semantics rather than a replacement for the right element.

Frequently asked questions

What is semantic HTML?
Semantic HTML uses elements that describe the meaning of their content, such as nav, article, and button, rather than generic containers like div and span. The meaning is available to browsers, screen readers, and search engines.
Why does semantic HTML matter for accessibility?
Because assistive technology relies on it. A button element is announced as a button, is focusable, and responds to Enter and Space. A styled div is announced as nothing and is unreachable by keyboard.
Does semantic HTML help SEO?
It helps indirectly. Search engines use structure to understand a page, and semantic elements make the structure explicit. Heading hierarchy and landmarks are the most relevant parts.
What is the difference between article and section?
An article is a self-contained piece of content that would make sense on its own, such as a blog post. A section is a thematic grouping within a larger document. If you cannot give it a heading, it is probably a div.
Should I use div at all?
Yes, for purely presentational grouping where no semantic element fits. A div is the right choice when you need a container for layout and nothing more.
What is the difference between button and a?
Use button for actions that do something, such as submitting a form or opening a dialog. Use a for navigation to another URL. The distinction matters for keyboard behaviour, screen readers, and right-click options.