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 Velloreth
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>
| Element | Meaning |
|---|---|
header | Introductory content, often a logo and nav |
nav | A block of navigation links |
main | The primary content, once per page |
aside | Tangentially related content, like a sidebar |
footer | Closing content, often links and copyright |
section | A thematic grouping, usually with a heading |
article | Self-contained content that stands alone |
Rules worth knowing:
- One
mainper page. It marks the primary content. headerandfootercan nest. A page header and an article header are both valid.navis for major navigation. A list of links in a footer does not neednavunless it is a navigation block.sectionneeds a heading. If you cannot give it one, use adiv.
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:
buttonfor actions — submit, open, close, toggle, delete.afor 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:
labelwithfor— 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
h1per page, describing the page’s main topic. - Do not skip levels. An
h2followed by anh4confuses 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
buttonfor actions andafor navigation. - Give every
sectiona heading, or use a div. - Keep one
h1and do not skip heading levels. - Label every form field with a real
label. - Use
divonly 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.